Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

My ApplesScript won't work, please help!

My AppleScript doesn't work. It says "The variable result is not defined". Here is my script:

display dialog "Hello, I am TalkBot. Talk to me whenever you like." with title "Designed by Connor Devlin ©McKeever Software" buttons {"Talk", "Cancel"} default button 1

set Talk to the button returned of the result

if Talk is "Talk" then choose from list {"Sports", "Movies", "School", "TV", "TalkBot", "Games", "McKeever Software", "Food", "London"} with prompt "What would you like to talk about, friend?"

set theAbout to the result


if theAbout is "Sports" then choose from list {"Baseball", "Soccer", "Football", "Rugby", "Cricket"}

set theSport to the result

if theSport is "Baseball" then display dialog "Good choice! What is your favorite team?" default answer ""

set theTeam to the text returned of the result

if theTeam is "Orioles" then display dialog "Cool. I'm don't like them, but I don't dislike them. I respect your choice."

if theTeam is "Red Sox" then display dialog "Really… You don't know how disappointed I am."

if theTeam is "Yankees" then display dialog "I'm not gonna even talk to you anymore…"

if theTeam is "Rays" then display dialog "Meh. There OK"

if theTeam is "Blue Jays" then display dialog "You stole R.A. Dickey! Give him back!"

if theTeam is "Braves" then display dialog "Not bad. I kind of like them."

if theTeam is "Marlins" then display dialog "Your logo looks like a unicorn threw up a rainbow on the letter M and a Marlin."

if theTeam is "Mets" then display dialog "I love you so much. They are the greatest team in the world (even if they suck)! I now respect you forever."

if theTeam is "Phillies" then display dialog "Go die in a hole!"

if theTeam is "Nationals" then display dialog "Yay! I like them too."

if theTeam is "White Sox" then display dialog "They're OK."

AppleScript-OTHER

Posted on Mar 10, 2013 10:03 AM

Reply
2 replies

Mar 10, 2013 10:28 AM in response to Jamesbondjapan

The built-in variable result contains the results of the last statement performed. In the case of choose from list, that result is a list, even if there is only one item, so your string comparison is failing. You should be coercing the result to text (or getting the first item of the list), although you should also maybe look into rearranging your queries and responses before you get lost.

Mar 10, 2013 10:32 AM in response to Jamesbondjapan

Your scripts logic is sketchy. Choose from list returns a list, so theAbout is set to {"Sports"}. {"Sports"} is not the same as "Sports" (one is a list and the other is text), so the second choose from list never gets run, so the result variable in the next line has no value. You should rewrite your choose form list sections on this pattern:


if Talk is "Talk" then

choose from list {"Sports", "Movies", "School", "TV", "TalkBot", "Games", "McKeever Software", "Food", "London"} with prompt "What would you like to talk about, friend?"

set theAbout to (item 1 of the result)

end if


and make sure that all of the choices are accounted for so that you never send an unset variable onward.

My ApplesScript won't work, please help!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.