I'm having trouble defining a variable for some reason... Help!

Applescript is butting heads with me left and right with this chunk of code… Why on earth is it insisting that qOne isn’t defined when it gets to “if qOne”?

on qZero()
	set qOne to ""
	display dialog "What would you like to do?" buttons {"Full OGM to MP4", "Demux OGM", "More Options"} default button "Full OGM to MP4"
	set {button returned:qOne} to result
end qZero

qZero()

if qOne = "More Options" then
	set qTwo to ""
	display dialog "What would you like to do?\" (Continued)" buttons {"Convert Audio Tracks", "Mux Audio to Video", "Even More Options"} default button "Even More Options"
	set {button returned:qTwo} to result
end if

if qTwo = "Even More Options" then
	set qThree to ""
	display dialog "What would you like to do?\" (Continued.)" buttons {"Convert AVI to MP4", "Ask Questions Again", "Quit"} default button "Ask Questions Again"
	set {button returned:qThree} to result
end if

if qThree = "Ask Questions Again" then
	qZero()
else if qThree = "Quit" then
	quit
end if

EDIT: Hey on a side note, is there a way to get more than 3 buttons on a dialog? Applescript says you can’t, but there’s got to be something… That would be a nice alternative to this multiple dialog crap I’ve got going on.

qOne is only defined in the scope of the qZero method. As soon as that method returns, it is removed from memory. You can solve this by either declaring qOne as a global or property, or by having qZero return the button returned somehow. Here’s my fix:

global qOne

on qZero()
	set qOne to ""
	display dialog "What would you like to do?" buttons {"Full OGM to MP4", "Demux OGM", "More Options"} default button "Full OGM to MP4"
	set {button returned:qOne} to result
end qZero

qZero()

if qOne = "More Options" then
	set qTwo to ""
	display dialog "What would you like to do?\" (Continued)" buttons {"Convert Audio Tracks", "Mux Audio to Video", "Even More Options"} default button "Even More Options"
	set {button returned:qTwo} to result
end if

if qTwo = "Even More Options" then
	set qThree to ""
	display dialog "What would you like to do?\" (Continued.)" buttons {"Convert AVI to MP4", "Ask Questions Again", "Quit"} default button "Ask Questions Again"
	set {button returned:qThree} to result
end if

if qThree = "Ask Questions Again" then
	qZero()
else if qThree = "Quit" then
	quit
end if

Sweet! That works just peachy. :smiley: Also, I noticed I had some quoting issues, but I fixed them too. I only noticed it because the blue code here online was spazzing out in the Applescript code box >.<

Fixed:

global qOne

on qZero()
	set qOne to ""
	display dialog "What would you like to do?" buttons {"Full OGM to MP4", "Demux OGM", "More Options"} default button "Full OGM to MP4"
	set {button returned:qOne} to result
end qZero

qZero()

if qOne = "More Options" then
	set qTwo to ""
	display dialog "\"What would you like to do?\" (Continued)" buttons {"Convert Audio Tracks", "Mux Audio to Video", "Even More Options"} default button "Even More Options"
	set {button returned:qTwo} to result
end if

if qTwo = "Even More Options" then
	set qThree to ""
	display dialog "\"What would you like to do?\" (Continued.)" buttons {"Convert AVI to MP4", "Ask Questions Again", "Quit"} default button "Ask Questions Again"
	set {button returned:qThree} to result
end if

if qThree = "Ask Questions Again" then
	qZero()
else if qThree = "Quit" then
	quit
end if

Not with AppleScript. However, you might be interest in choose from list (which is part of StandardAdditions):

choose from list {"Full OGM to MP4", "Demux OGM", "Convert Audio Tracks", "Mux Audio to Video", "Convert AVI to MP4"} OK button name "Continue"
tell result
	if it is false then error number -128 -- cancel
	set choice to first item
end tell

Bruce, your so awesome!! :smiley: That’s way better :wink:

EDIT: Maybe I should start using the dictionary function a bit more. :stuck_out_tongue: I tend to get confused when trying to apply the info found in the dictionary to a script so I just don’t bother usually.

SK8,

For the 411 on variables (global and local) as well as properties, see my article “Technical Tutorial: Variable Scope in Applescript and Applescript Studio” in Unscripted that was put up a while back (last month?).

Also, Craig Smith has a great article in his beginner’s series that covers both variables and dictionaries - “AppleScript Tutorial for Beginners II - Variables and Dictionaries.”

Learning to read the dictionary of the application you’re using will help you immensely and will allow you to write MUCH more amazing code. :cool:

Adds said links to coding sub folder of mac folder of bookmarks menu :wink:

EDIT: Heh, your links are all messed up >.<

Fixed:
AppleScript Tutorial for Beginners II - Variables and Dictionaries
Technical Tutorial: Variable Scope in Applescript and Applescript Studio

AH, that’s where I left those messed up links. :rolleyes:

I thought I remembered over-formatting some links but couldn’t find where it was. I’ve got a script that makes a href=“blah blah” type links and forgot that in BBCode it’s ‘URL’ not ‘A.’

Heh, that just gave me a good idea for a script. :wink: When you copy something, run a scrip that asks you what kind of bbcode it is or even html and you choose from a list and it modifies whatever is saved to the clipboard so it’s formatted the way you want. I could probably manage that, but I doubt I would know all the things you would want it to format to. :stuck_out_tongue: Off the top of my head i’m thinking Applescript, Code, Quote, URL, IMG in bbcode and url’s in html. I guess just anything you would find on a bbcode forum :wink:

Now that’s thinking like a scripter! :wink: