Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 26, 2006, 05:20 PM   #1
Unorthodox
macrumors 65816
 
Unorthodox's Avatar
 
Join Date: Mar 2006
Location: Not at the beach...
Exit applescript

How does one go about telling a script to quit, even if it's only half way thorough?

For example:
Quote:
display dialog "Do you want to quit?" buttons {"Yes","No"}
if the button returned of the result is "Yes" then
--This is where I got stumped
end
beep 5
What command will exit the script immediately if the button "Quit" is pressed and not continue on and beep.
I know if you use "Cancel" as a button that will exit the script.
How do I do that, but with a different word on the button?
__________________
Advertise your site, software, or service in this space and be seen over 100,000ish times per day by your target audience. Click here for info.
Unorthodox is offline   0 Reply With Quote
Old Sep 26, 2006, 05:36 PM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Use "return"

Code:
display dialog "HEY"
return
beep
"beep" never gets called.
kainjow is offline   0 Reply With Quote
Old Sep 26, 2006, 06:12 PM   #3
Unorthodox
Thread Starter
macrumors 65816
 
Unorthodox's Avatar
 
Join Date: Mar 2006
Location: Not at the beach...
Look at this example:
Code:
on potato()
	display dialog "Cheese" buttons {"Quit","Play"}
	if the button returned of the result is "Quit" then
		return
	else
		potato()
	end if
	beep
end potato
set cheese to true
potato()
If you hit the button quit. it quits.
But.....
If you hit the button play, it repeats (as it's supposed to).
Now if you hit quit it will beep.
What gives?
__________________
Advertise your site, software, or service in this space and be seen over 100,000ish times per day by your target audience. Click here for info.
Unorthodox is offline   0 Reply With Quote
Old Sep 26, 2006, 06:18 PM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
"return" exits from the current function. It doesn't affect where the function was called from originally.

The code within a function doesn't replace the name of the function where it's called.

Your code will continue to go on forever if you keep pressing Play.
kainjow is offline   0 Reply With Quote
Old Sep 26, 2006, 06:34 PM   #5
Unorthodox
Thread Starter
macrumors 65816
 
Unorthodox's Avatar
 
Join Date: Mar 2006
Location: Not at the beach...
Quote:
Originally Posted by kainjow
"return" exits from the current function. It doesn't affect where the function was called from originally.

The code within a function doesn't replace the name of the function where it's called.

Your code will continue to go on forever if you keep pressing Play.
I want it to go on forever when you press play.
But I want it to stop when you press quit.

Do you know anyway to do this?

I'm trying to make a blackjack game just using AppleScript.
The part I'm having trouble on is if you win/lose, it asks you if you want to play again or stop playing.
__________________
Advertise your site, software, or service in this space and be seen over 100,000ish times per day by your target audience. Click here for info.

Last edited by Unorthodox; Sep 26, 2006 at 06:40 PM.
Unorthodox is offline   0 Reply With Quote
Old Sep 26, 2006, 06:51 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Try a loop instead of a recursive function:

Code:
on potato()
	set done to false
	repeat while done is false
		display dialog "Cheese" buttons {"Quit", "Play"}
		if the button returned of the result is "Quit" then
			set done to true
		end if
	end repeat
	
	beep
end potato

potato()
kainjow is offline   0 Reply With Quote
Old Sep 26, 2006, 07:20 PM   #7
Unorthodox
Thread Starter
macrumors 65816
 
Unorthodox's Avatar
 
Join Date: Mar 2006
Location: Not at the beach...
That's a good idea.
One more question though.
Is is there a command that makes the script start from the beginning of a repeat?



Edit: Never mind. Figured it out.
Thanks so much for all your help kainjow!
Have a cookie.
__________________
Advertise your site, software, or service in this space and be seen over 100,000ish times per day by your target audience. Click here for info.
Unorthodox is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone: Can't Exit Out Of Safe Mode? jennn Jailbreaks and iOS Hacks 4 Nov 13, 2013 03:25 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 28, 2013 11:38 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Applications and Mac App Store 0 Oct 28, 2013 11:32 PM
'on volume' - cannot switch off/exit, need help Tory2013 Mac Basics and Help 2 Jun 18, 2013 02:25 PM
iPhone: Exit Safe Mode Homer3 Jailbreaks and iOS Hacks 1 Feb 4, 2013 01:37 PM

Forum Jump

All times are GMT -5. The time now is 01:30 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC