Module timer
Functions for handling timers (running code after a delay)
Global functions
Timer.registerTimer (delayMs, repeat, fn) | register a new timer. |
Timer.run (delayMs, fn) | Runs a function once after some delay. |
Class Timer
timer:cancel () | cancel a timer object. |
timer:start () | start a timer object. |
Global functions
- Timer.registerTimer (delayMs, repeat, fn)
-
register a new timer.
This returns a timer object which must the be started.
For most usage in lua progs, Timer.run will be simpler to use.
Parameters:
- delayMs number the number of milliseconds to wait
- repeat boolean if true, the timer will continue firing every delayMs. If false, it will fire only once.
- fn function the function to run when the timer fires.
Returns:
-
Timer
the newly registered timer
Usage:
Timer.registerTimer(1000, false, function() self:sayTo(ch, "Hello there, welcome to the room.") end):start()
- Timer.run (delayMs, fn)
-
Runs a function once after some delay.
Parameters:
- delayMs number The number of milliseconds to wait
- fn function The function to run
Returns:
-
Timer
The timer object, in case you need to cancel it
Usage:
self:onSpeech("help", function(self, ch) -- Wait 3 seconds, then respond to the character. Timer.run(3000, function() self:sayTo(ch, "Oh, you can help me?") self:sayTo(ch, "I need ten pieces of nerf meat.") end) end)
Class Timer
Functions on character variables