Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 5, 2013, 04:59 AM   #1
LBoy3550
macrumors newbie
 
Join Date: Mar 2013
Having trouble with applescript!

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 robbieduncan; Mar 5, 2013 at 05:43 AM. Reason: Please use the code tags :)
LBoy3550 is offline   0 Reply With Quote
Old Mar 5, 2013, 06:25 AM   #2
superscape
macrumors regular
 
Join Date: Feb 2008
Location: 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!
superscape is offline   0 Reply With Quote
Old Mar 5, 2013, 03:54 PM   #3
LBoy3550
Thread Starter
macrumors newbie
 
Join Date: Mar 2013
Thanks so much superscape!
It worked! I cant wait to show all my friends.
Thanks again

LBoy
LBoy3550 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
Applescript If exists trouble, please help cjaneway Mac Programming 1 Apr 24, 2014 02:35 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 trouble with setting default location to choose file TexasStation Mac Programming 2 Sep 4, 2013 01:35 PM
Applescript trouble - testing against Label Index Terminal Frost Mac Programming 2 Jan 16, 2013 08:28 PM
Resolved: Applescript: Launching self-contained app trouble 1theo0 Mac Programming 2 Oct 15, 2012 09:04 AM

Forum Jump

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

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

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