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

Is there a way to refer, or go back to a part of a code

Hey all,

Is there a way to goto or refer to a previous part of a code from another part. What I have is a window showing the viewer 2 buttons, I want to make it go back to that home screen after they click on one of the two buttons. I included the part of the code below, so if they click button "text" after they read This is a program and click Ok, it should go back to the first display dialog.Any ideas??


display dialog ¬

"Sample Text" buttons {"Text, "Text 2}

if button returned of result is "What is this" then

display dialog ¬

"This is a program" buttons {"Ok"}


else

display dialog ¬

"Text Text Text"



Thanks a lot, AppleTardis

MacBook Air, Other OS

Posted on Apr 26, 2016 3:48 PM

Reply
Question marked as Best reply

Posted on Apr 26, 2016 5:28 PM

Not sure if this is what you are looking for but this will start your script over at the beginning, until you click "Cancel."


SG


display dialog ¬

"Sample Text" buttons {"Text1", "Text 2"}

if button returned of result is "Text1" then


display dialog ¬

"This is a program" buttons {"Ok", "Cancel"}

else


display dialog ¬

"Text Text Text" buttons {"Ok", "Cancel"}

end if

run me

3 replies
Question marked as Best reply

Apr 26, 2016 5:28 PM in response to appletardis

Not sure if this is what you are looking for but this will start your script over at the beginning, until you click "Cancel."


SG


display dialog ¬

"Sample Text" buttons {"Text1", "Text 2"}

if button returned of result is "Text1" then


display dialog ¬

"This is a program" buttons {"Ok", "Cancel"}

else


display dialog ¬

"Text Text Text" buttons {"Ok", "Cancel"}

end if

run me

Apr 26, 2016 11:54 PM in response to SGIII

'run me' is a great way to re-run the entire script, but falls down if the code is a small snippet within a larger script.

For that you likely need a repeat loop with a flag to exit the loop:


-- any code before the dialog


set done to false

repeat until done is true


display dialog ¬

"Sample Text" buttons {"Text1", "Text 2"}

if button returned of result is "Text1" then

set secondDialog to display dialog"This is a program" buttons {"OK", "Done"}

else

set secondDialog to display dialog"Text Text Text" buttons {"OK", "Done"}

end if

if button returned of secondDialog is "Done" then set done to true

end repeat


-- any code to run after the dialogs are 'Done'


In this way you can have setup code before your dialogs, and additional code after them and just loop through the part in the middle.

Is there a way to refer, or go back to a part of a code

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