Without line numbers and “go to” statements, how do you skip large sections of the code?
Lets say I have 3 buttons and 3 actions. One button executes the first part of a script, the second button executes the second part, and the third executes the ENTIRE script. How could you pull this off?
display dialog buttons {"Do One", "Do Two", "Do All"}
get button returned of result
if result is "Do One" then
yourFirstPart()
else if result is "Do Two" then
yourSecondPart()
else
yourFirstPart()
yourSecondPart()
end if
on yourFirstPart()
--whatever 1
end yourFirstPart
on yourSecondPart()
--whatever 2
end yourSecondPart
display dialog buttons {"Do One", "Do Two", "Do All"}
set theButton to button returned of result
if theButton is "Do One" or theButton is "Do All" then
--whatever 1
end if
if theButton is "Do Two" or theButton is "Do All" then
--whatever 2
end if
set Proc to button returned of (display dialog "Which Process do you want?" buttons {"Process #1", "Process #2", "Processes 1/2/3"})
set msg to ""
if Proc = "Process #1" then
Part_1()
display dialog msg
return
else if Proc = "Process #2" then
Part_2()
display dialog msg
return
else if Proc = "Processes 1/2/3" then
Part_1()
Part_2()
Part_3()
display dialog msg
end if
to Part_1()
set my msg to "Part_1 done"
end Part_1
to Part_2()
set my msg to my msg & return & "Part_2 done"
end Part_2
to Part_3()
set my msg to my msg & return & "Part_3 done"
end Part_3
I have a similar question but I would want to add it to the end of the script.
Like if you want to do the second part agian can you have the script start from the point you choose? Skipping the begining of the script where you already answered a common question.
on run
display dialog buttons {"Do One", "Do Two", "Do All"}
get button returned of result
if result is "Do One" then
yourFirstPart()
else if result is "Do Two" then
yourSecondPart()
else
yourFirstPart()
yourSecondPart()
end if
display dialog buttons {"Do Two Again", "Done"}
if button returned of result is "Do Two Again" then yourSecondPart()
end run
on yourFirstPart()
--whatever 1
end yourFirstPart
on yourSecondPart()
--whatever 2
end yourSecondPart
Thanks guys! I haven’t done any serious programming since my Apple IIe and Atari 400/800 days, so it’s going to take me a while to adjust to doing things without line numbers, “for/next” loops and “go to” statements.
And I’m not sure if I entirely understand handlers, but I’ll play with them until I figure them out. Heh, kind of like women in the regard!
Bruce thanks for the example on handlers. I think I understand how they work, but it seems you can not bring an answer from one part to another. Lets say I answered a question in yourfirstpart() and I needed that answer to carry through to yoursecondpart() and yourthirdpart(). Is this possilbe I’m been trying to work it out but with no luck.
property FirstAns : missing value
property SecAns : missing value
display dialog buttons {"Do One", "Do Two", "Do All"}
get button returned of result
if result is "Do One" then
yourFirstPart()
else if result is "Do Two" then
yourSecondPart()
else
yourFirstPart()
yourSecondPart()
end if
display dialog buttons {"Do Two Again", "Done"}
if button returned of result is "Do Two Again" then yourSecondPart()
on yourFirstPart()
--whatever 1
--set my FirstAns to a variable here
end yourFirstPart
on yourSecondPart()
--whatever 2
--set my SecAns to something from here
end yourSecondPart
Adam Thanks alot that worked perfectly. I’m learning more each day with the help of everyone in the forums. Now if I can just get my pesky spot color problem solved I’ll be in business.