Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LBoy3550

macrumors newbie
Original poster
Mar 5, 2013
2
0
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
 
Last edited by a moderator:

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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!
 

LBoy3550

macrumors newbie
Original poster
Mar 5, 2013
2
0
Thanks so much superscape!
It worked! I cant wait to show all my friends.
Thanks again

LBoy
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.