Using a function that can be called at a later time can be helpful when organizing the timing of the appearance of your game objects in an application. The timer library will allow us to handle our functions in a timely manner.
The timer
function enables you to trigger events at a specific delay (in milliseconds) of your choosing.
timer.performWithDelay( delay, listener [, iterations] )
Invokes the listener after a delay in milliseconds and returns a handle you can pass to
timer.cancel()
to cancel the timer before it invokes the listener.Example:
local function myEvent() print( "myEvent called" ) end timer.performWithDelay( 1000, myEvent )
timer.cancel( timerId )
Cancels a timer operation initiated with
timer.performWithDelay()
.Parameters:
timerId
: Handle returned by the call totimer.performWithDelay()
.
Example:
local count = 0 local function myEvent() count = count + 1 print( count ) if count >= 3 then timer.cancel( myTimerID ...