How to get returned value from handler in another script object

I’m writing a “Speak & Spell” application in AppleScript for practice, and I can’t figure out how to access a returned variable from a handler in another “script” object. The other script object in question works something like this:

script SpellingMachine
	to sayNowSpell by wordToSay
		say "Now spell     " & wordToSay
		repeat
			set spellingWord_di to display dialog "What is your answer?" default answer "enter answer here" buttons {"Answer", "Repeat Word"} default button 1
			if button returned of spellingWord_di is equal to "Repeat Word" then
				say "Now spell     " & wordToSay
			end if
			if button returned of spellingWord_di is equal to "Answer" then
				exit repeat
			end if
		end repeat
		if text returned of spellingWord_di is equal to wordToSay then
			return true
		else
			return false
		end if
	end sayNowSpell
end script

As I said before, how would I do something like “Set isCorrect to tell SpellingMachine to sayNowSpell by wordToSpell” so I could do something based on if the user spelled the word properly?

As you’ve structured it:

script SpellingMachine
	to sayNowSpell by wordToSay
		set tStart to say "Now spell     " & wordToSay
		repeat
			set spellingWord_di to display dialog "What is your answer?" default answer "enter answer here" buttons {"Answer", "Repeat Word"} default button 1
			if button returned of spellingWord_di is equal to "Repeat Word" then
				say "Now spell     " & wordToSay
			end if
			if button returned of spellingWord_di is equal to "Answer" then
				exit repeat
			end if
		end repeat
		if text returned of spellingWord_di is equal to wordToSay then
			return true
		else
			return false
		end if
	end sayNowSpell
end script

sayNowSpell of SpellingMachine by SpellingMachine's "separate"

Hi,

If you want to load the script as a script object into another script, save it without the script - end script lines.

tell SpellingMachine to set isCorrect to sayNowSpell by wordToSpell
-- or:
set isCorrect to sayNowSpell of SpellingMachine by wordToSpell
-- or:
set isCorrect to (sayNowSpell by wordToSpell) of SpellingMachine -- The parentheses stop the line from rearranging.
-- or:
set isCorrect to SpellingMachine's (sayNowSpell by wordToSpell) -- Ditto.

if (isCorrect) then
	-- do something
end if

-- or:
if (SpellingMachine's (sayNowSpell by wordToSpell)) then
	-- do something
end if

-- and so on ..