• 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: Yvan KOENIG <email@hidden>
  • Date: Sun, 10 Jan 2010 22:15:34 +0100


Le 10 janv. 2010 à 21:55, Jack Schwart a écrit :

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

In fact the variable ValidInput is not changed.
It's absolutely useless in the handler.

The loop is exited when the instruction 
return NoRange is executed.

The handler may be edited as:
on getplayerinput()


repeat -- loop until valid input is collected


--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

or :

on getplayerinput()


repeat -- loop until valid input is collected


--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"
exit repeat
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


return NoRange -- Return the player's input
end getplayerinput

In this late version, the 'exit repeat' is explicit.
It was implicit in the original code and in the 1st edited version.

Yvan KOENIG (VALLAURIS, France) dimanche 10 janvier 2010 22:14:54


 _______________________________________________
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: Snow Leopard osax security and 'run script' with parameters
  • Next by Date: Re: how?
  • Previous by thread: how?
  • Next by thread: Re: how?
  • Index(es):
    • Date
    • Thread