timer.performWithDelay()

Overview

Calls a specified function after a delay. This function returns a table that can be used with other timer functions. For example, the returned table can be passed to timer.cancel() to cancel the invocation of the specified listener.

Gotchas

Timers run on system time. If the app is suspended, running timers will not be automatically paused, meaning that when the app is resumed, all timers that would have completed/triggered during the suspended period will trigger immediately. Thus, if you have running timers that are not paused (in code) upon suspension of the app, you should handle this task by calling timer.pause() on all applicable timers.

Syntax

timer.performWithDelay( delay, listener [, iterations] )

delay (required)

Number. The delay in milliseconds, for example, 1000 = 1 second. Note that timers cannot execute faster than the runtime framerate of the app. For example, if the framerate of the app is 60 frames per second, as defined in the config.lua file (guide), the shortest delay for a timer is approximately 16.667 milliseconds (1000/60 = ~16.667).

listener (required)

Listener. The listener to invoke after the delay. This may be either a function listener or a table listener. If a table listener, it must have a timer method because timer events are sent to the listener.

iterations (optional)

Number. Optionally specifies the number of times listener is to be invoked. By default, it is 1; pass 0 or -1 if you want the timer to loop forever.