Language

Timer:add


Timer:add(string id, int delay, callback)

Description

Create a function that will be automatically called after delay seconds. Do not forget to add Timer:update() in your onUpdate function!

Parameters

id
The unique ID of the timer
delay
Delay in seconds to wait
callback
A function to call. Can be anonymous or can refer to a function

Examples

Simple timer

  1. local boss = getEntity("boss")
  2.  
  3. function startAttack()
  4.     -- To implement
  5. end
  6.  
  7. function onReset()
  8.     Timer:removeAll()
  9. end
  10.  
  11. function onUpdate(elapsed)
  12.     Timer:update()
  13. end
  14.  
  15. function onTrigger(name, state)
  16.     if name == "start_boss" then
  17.         Timer:add("boss_move", 1.0, function() boss:moveTo(10, 10, 0.2, 0) end)
  18.         Timer:add("boss_attack", 2.0, startAttack)
  19.     end
  20. end