• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how?


  • Subject: Re: how?
  • From: Barry Wainwright <email@hidden>
  • Date: Sun, 10 Jan 2010 21:22:36 +0000

Quick answer - it doesn't.

Slightly longer answer:

The loop is exited by the 'return NoRange' statement. This only occurs after the 'if' statement determines the input has been valid and the NoRange variable set accordingly.

The ValidInput variable is set to false at the start of the routine and never used. This routine would work just as well if the 'repeat until ValidInput - true' statement just read 'repeat':

on GetPlayerInput()
repeat
set NoRange to text returned of (display dialog ¬
"What is the highest number that can be selected when " & ¬
"creating a lottery ticket?" default answer ¬
"44" buttons {"OK"} with title GameTitle)
if (NoRange > 2) and (NoRange < 60) then
set NoRange to NoRange as integer -
return NoRange 
else 
display dialog "Error:  You must enter an integer value " & ¬
"between 3 and 59" with title GameTitle
end if
end repeat
end GetPlayerInput

-- 
Barry



On 10 Jan 2010, at 20:55, Jack Schwart wrote:

Hi, I am trying to teach myself applescript.  I went through Jerry Lee Ford, Jr.'s book, Applescript for the Absolute Beginner, and understood everything except this following code block.  Can any one help me figure out how the variable "ValidInput" switches to "true" and ends the loop?

Thanks, Jack

--******** GetPlayerInput handler ******************

--This handler prompts the player to tell the game the range of 
--numbers from which lottery ticket numbers should be selected
on GetPlayerInput()

--This variable is used to control loop execution
set ValidInput to false

repeat until ValidInput = true -- loop until valid input is collected

--Question,:how does ValidInput switch to true???

--Prompt the player to specify the range of numbers to be used
set NoRange to text returned of (display dialog ¬
"What is the highest number that can be selected when " & ¬
"creating a lottery ticket?" default answer ¬
"44" buttons {"OK"} with title GameTitle)
--The range must be at least 3 and no larger than 59
if (NoRange > 2) and (NoRange < 60) then
set NoRange to NoRange as integer --Convert the player input
--Question:  Why do I need this step???? A: see page 101 "Coercion"
return NoRange -- Return the player's input
else -- Display an error message if the input is not valid
display dialog "Error:  You must enter an integer value " & ¬
"between 3 and 59" with title GameTitle
end if

end repeat

end GetPlayerInput

= Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users This email sent to email@hidden
References: 
 >how? (From: Jack Schwart <email@hidden>)

  • Prev by Date: Re: how?
  • Next by Date: Re: how?
  • Previous by thread: Re: how?
  • Next by thread: Re: how?
  • Index(es):
    • Date
    • Thread