error "«script» doesn’t understand the dialog message."

I keep getting this error

on my script. I really want to make it work. Can someone help?

Script


on run
	set L to (do shell script "whoami") & "~Command: "
	begin()
	repeat
		set command to missing value
		set subcom to missing value
		set subcom2 to missing value
		set command to dialog(L)
		if command is "quit" or command is "end" then
			done()
		else if command is "network" then
			set subcom to dialog("Do you want to ping or (pong) whois?")
			if subcom is "ping" then
				set thesite to dialog("What site do you want to ping?")
				set X to dialog("This might take time. Continue?")
				if X is in {"Y", "YES", "YEAH", "SURE", "POSITIVE", "PING", " Y", " YES", " YEAH", " SURE", " POSITIVE", " PING", "Y ", "YES ", "YEAH ", "SURE ", "POSITIVE ", "PING "} then
					set subcom2 to do shell script "ping -c " & numb & space & quoted form of thesite
				end if
			else if subcom is "pong" then
				display("It was a joke!")
			else if subcom is "whois" then
				set thesite to dialog("What site do you want to whois?")
				set subcom2 to do shell script "whois " & quoted form of thesite
			end if
			display(subcome2)
		else
			display("The command \"" & command & "\" does not exist.")
		end if
	end repeat
end run

on begin()
	tell application "TextEdit"
		try
			close every document saving yes
		on error e
			if e is "TextEdit got an error: AppleEvent handler failed." then
				close every document saving no
			else
				display dialog "There was a problem trying to open. " & return & return & return & e
			end if
		end try
		set doc to make new document
		set text of doc to "Welcome. Type \"Help\" for help."
	end tell
end begin

on dialog(T)
	tell application "TextEdit"
		set text of front document to the text of front document & return & T
		activate
		repeat
			activate
			set thetext to text of front document
			if the last character of thetext is (ASCII character 10) then
				exit repeat
			end if
		end repeat
		set numb to (count (paragraphs of thetext)) - 1
		set mydialog to paragraph numb of thetext as string
		activate
		set AppleScript's text item delimiters to T
		set dialog to text item 2 of mydialog as string
		activate
	end tell
	return dialog
end dialog

on display(T)
	tell application "TextEdit" to set the text of the front document to the text of the front document & T & return
end display

on done()
	tell application "TextEdit"
		set the text of the front document to "Quiting..."
		delay 5
		close the front document without saving
		quit
	end tell
end done

Hi,

there’s a naming clash with the handler dialog() and the variable dialog
Use a different name fo the variable.

btw: a paragraph and a text item is always a string, both as string coercions are useless
and don’t forget to reset text item delimiters


.
set mydialog to paragraph numb of thetext
		activate
		set AppleScript's text item delimiters to T
		set d to text item 2 of mydialog
		set AppleScript's text item delimiters to {""}
.