Create Timeout objects

-- Lingo syntax when scriptExecutionStyle is set to 9 
variableName = timeout().new(timeoutName, timeoutPeriod, #timeoutHandler, {, targetObject}) 
 
-- Lingo syntax when scriptExecutionStyle is set to 10 
variableName = timeout().new(timeoutName, timeoutPeriod, timeoutHandler, targetObject) 
variableName = new timeout(timeoutName, timeoutPeriod, timeoutHandler, targetObject) 
 
// JavaScript syntax 
variableName = new timeout(timeoutName, timeoutPeriod, timeoutFunction, targetObject)

This statement uses the following elements:

  • variableName is the variable you are placing the Timeout object into.

  • timeout indicates which type of Lingo object you are creating.

  • timeoutName is the name you give to the Timeout object. This name appears in the timeOutList. It is the #name property of the object.

  • new creates a new object.

  • intMilliseconds indicates the frequency with which the Timeout object should call the handler you specify. This is the #period property of the object. For example, a value of 2000 calls the specified handler every 2 seconds.

  • #handlerName is the name of the handler you want the object to call. This is the #timeOutHandler property of the object. You represent it as a symbol by preceding the name with the # sign. For example, a handler called on accelerate would be specified as #accelerate.

  • targetObject indicates which child object’s handler should be called. This is the #target property of the object. It allows specificity when many child objects contain the same handlers. If you omit this parameter, Director looks for the specified handler in the movie script.

The following statement creates a Timeout object named timer1 that calls an on accelerate handler in the child object car1 every 2 seconds:

-- Lingo syntax 
myTimer = timeOut("timer1").new(2000, #accelerate, car1)

To determine when the next timeout message will be sent from a particular Timeout object, check its #time property. The value returned is the point in time, in milliseconds, when the next timeout message will be sent. For example, the following statement determines the time when the next timeout message will be sent from the Timeout object timer1 and displays it in the Message window:

-- Lingo syntax 
put(timeout("timer1").time)