Having trouble with applescript!

Discussion in 'Mac Programming' started by LBoy3550, Mar 5, 2013.

  1. LBoy3550, Mar 5, 2013
    Last edited by a moderator: Mar 5, 2013

    macrumors newbie

    #1
    So im trying to do something but when i try and compile applescript says
    "Expected end of line, etc. but found “repeat”." Can anyone help me?
    P.S. this is the code VVVVVVVVVV
    Code:
    --Set Random Number
    set randomNumber to random number from 1 to 10
    --Boolean to Test if Script Should be Repeated
    set repeatTest to true
    --If Result Is a Number, Change to True and See if the Number is Between 1 and 10
    set testNumbers to false
    --If Result Passes All Previous Tests, is it Correct?
    set winningTest to false
    --Count Number of Guesses
    set tryCount to 0
    --Generic Dialog Handler
    on dialogBox(theMessage)
    	display dialog theMessage
    end dialogBox
    --Repeat if Any Tests Are Failed
    repeat while (repeatTest = true)
    	--Display Dialog & Get Result
    	display dialog "Choose a number 1-10" default answer "Enter Only Numbers 1-10" default button 2
    	set theAnswer to (text returned of result)
    	--Is Result a Number?
    	try
    		set theAnswer to theAnswer as number
    		set testNumbers to true
    	on error
    		dialogBox("Invalid Input")
    	end try
    	--Is Result Between 1 and 10?
    	if (testNumbers = true) then
    		--Test for Correct Numbers
    		if theAnswer < 1 then
    			dialogBox("Invalid Input")
    		else if theAnswer < 11 then
    			set repeatTest to false
    			set winningTest to true
    		else
    			dialogBox("Invalid Input")
    		end if
    	end if
    	--Is Result the Correct Answer?
    	if winningTest = true then
    		if theAnswer = randomNumber then
    			display dialog "You Guessed it!" buttons "Open Minecraft"
    			if the button returned of the result is "Open Minecraft" then
    			tell application "MinecraftSP"
    			launch
    			end tell
    		else
    			dialogBox("Try Again!")
    			set repeatTest to true
    			set tryCount to tryCount + 1
    		end if
    	end if
    end repeat
    
     
  2. macrumors 6502

    superscape

    #2
    Yup...

    Hi, you forgot an 'end if'. Instead of:

    Code:
    	
    if winningTest = true then
    		if theAnswer = randomNumber then
    			display dialog "You Guessed it!" buttons "Open Minecraft"
    			if the button returned of the result is "Open Minecraft" then
    			tell application "MinecraftSP"
    			launch
    			end tell
    		else
    			dialogBox("Try Again!")
    			set repeatTest to true
    			set tryCount to tryCount + 1
    		end if
    	end if
    
    ...you want...


    Code:
    	
    if winningTest = true then
    		if theAnswer = randomNumber then
    			display dialog "You Guessed it!" buttons "Open Minecraft"
    			if the button returned of the result is "Open Minecraft" then
    			    tell application "MinecraftSP"
    			    launch
    			    end tell
                            end if --I added this line!
    		else
    			dialogBox("Try Again!")
    			set repeatTest to true
    			set tryCount to tryCount + 1
    		end if
    	end if
    

    Hope that helps!
     
  3. macrumors newbie

    #3
    Thanks so much superscape!
    It worked! I cant wait to show all my friends.
    Thanks again

    LBoy
     

Share This Page