Results 1 to 3 of 3
  1. #1


    Member Since
    Feb 12, 2012
    Posts
    2
    applescript help
    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

  2. #2

    Mark FX's Avatar
    Member Since
    Aug 13, 2011
    Location
    West Sussex, UK
    Posts
    186
    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

  3. #3

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Applescript
    By EdMarx in forum OS X - Apps and Games
    Replies: 0
    Last Post: 02-10-2012, 04:06 AM
  2. Applescript
    By SgtDave in forum OS X - Development and Darwin
    Replies: 6
    Last Post: 01-19-2011, 03:50 PM
  3. Applescript help please?
    By thtguyjosh in forum OS X - Apps and Games
    Replies: 8
    Last Post: 08-22-2010, 07:22 PM
  4. Applescript
    By nixonbw in forum OS X - Operating System
    Replies: 0
    Last Post: 07-17-2008, 07:00 PM
  5. AppleScript
    By TehHero in forum OS X - Apps and Games
    Replies: 0
    Last Post: 01-26-2008, 09:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •