Skip to content
DizzasTeR edited this page Feb 21, 2021 · 4 revisions

create

Creates a timer

Timer Timer.create(function callback, int interval, int repeat [, ...optionalParameters])

Parameters

  • function callback — A handler function to be called
  • int interval — Timer interval in miliseconds (Minimum interval allowed is 50ms)
  • int repeat — How many times should the timer repeat or -1 to repeat indefinitely

Returns

Instance - Timer instance/object if the timer was created successfully, nil if something went wrong.


Note: Hidden Handler Var

When a timer callback/handler is executed, a hidden thisTimer variable is passed which references the current Timer instance being executed. This can be used to neatly deal with timers which aren't stored in a variable. Check Timer.destroy page example to see how its used.


Example

Timer.create(function(myNum, myMsg)
    Logger.info("["..myNum.."] -> "..myMsg) 
end, 1000, 1, 100, "My Message")

Example #2

Timer.create(function(data)
    iprint(data)
end, 1000, 1, {100, "My other message", secret = "value"})
Clone this wiki locally