New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Ľ Advice and insight from world-class Apple enthusiasts Ľ Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

applescript help


Post Reply New Thread Subscribe

 
Thread Tools
primrey

 
Member Since: Feb 12, 2012
Posts: 2
primrey is on a distinguished road

primrey is offline
Please check the stats part of this is not working
Code:
repeat
	set statswin to 0
	set statsLoser to 0
	set statsplays to 0
	set x to some item of "1234556789" as number
	display dialog "Guess a number between 1 and 9" default answer "Insert number here" buttons {"OK", "Stats"} default button 1
	if the button returned of the result is "Stats" then
		display dialog "wins " & statswin
		display dialog "Loses " & statsLoser
		display dialog "Total games " & statsplays
	else
		
		try
			set theAnswer to (text returned of result) as number
		on error
			display dialog "Invalid Input"
			say "Invalid input"
			return
		end try
		
		--Test for Correct Numbers
		if theAnswer < 1 or theAnswer > 10 then
			set theTest to 0
		else
			set theTest to 1
		end if
		
		--Return Comments to user
		if theTest = 0 then
			display dialog "Invalid Input"
		else
			set m to theAnswer * x
			set a to 1
			if m is in {1, 4, 9, 16, 25, 36, 49, 64, 81} then
				set a to 2
			end if
			if a is equal to 2 then
				
				display dialog "winner"
				set statswin to statswin + 1
				set statsplays to statsplays + 1
			else
				display dialog "loser"
				set statsLoser to statsLoser + 1
				set statsplays to statsplays + 1
			end if
		end if
	end if
end repeat
end
end
QUOTE Thanks
Mark FX

 
Mark FX's Avatar
 
Member Since: Aug 13, 2011
Location: West Sussex, UK
Posts: 170
Mark FX has a spectacular aura about

Mark FX is offline
You have put the statswin, statsLoser, and statsplays variables inside the repeat loop, and
are setting them back to zero each time the loop runs, try putting them outside the repeat
loop, then they will retain tere values.

Like this

Code:
set statswin to 0
set statsLoser to 0
set statsplays to 0
repeat
        --All the other game code in here
end reepat
Also I noticed that your repeat loop has no end, so the game will go on forever.
Try setting the repeat loop to a certain number of tries at the game.

Like this.

Code:
repeat 10 times

end repeat
Hope this helps.

Regards Mark
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 18,352
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
You're also setting x to a value between one and ten but you've listed five twice:
Code:
set x to some item of "1234556789" as number
Any particular reason you're doing this in AppleScript? AS is designed to let you script applications and isn't the best language for general scripting. It will work but you might be better off with another language.

Important Links: Community Guidelines : Use the reputation system if you've been helped.
M-F Blog :: Write for the blog
Writing a Quality Post
QUOTE Thanks

Post Reply New Thread Subscribe


« Just a question | Creating a package for MAC OS. multi-user environment »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Restarting Application using Applescript from Java? iwebdevelop OS X - Development and Darwin 7 08-10-2011 08:53 AM
Applescript help with serial port access ljimber OS X - Development and Darwin 0 06-24-2011 12:46 PM
help needed to link up buttons on HUD Window to Applescript nick_harambee OS X - Development and Darwin 0 09-30-2010 09:26 AM
newbie question on XCode 3.2: how to populate pop up buttons/link to applescript nickharambee OS X - Operating System 0 10-21-2009 08:10 AM
[ANN] New comprehensive AppleScript book hanaan OS X - Development and Darwin 0 11-06-2004 08:28 PM

All times are GMT -4. The time now is 02:58 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?