wolfhacklua API 1.1 Forum

timer

Run a function later, or repeatedly. Timers run on the script's own clock inside the frame budget.

since 1.0no permission needed

At most 64 timers per script. All timers are cancelled when the script stops. A timer callback has the same 3 ms budget as any other callback, so keep it short.

Reference#

timer.after#since 1.0

timer.after(seconds: number, fn: function): integer

Calls fn once after the delay.

ParameterTypeDescription
secondsnumberDelay before the call.
fnfunctionCalled once.
ReturnsDescription
integerA timer id for timer.cancel.
lua
timer.after(3, function() log.info("three seconds later") end)

timer.every#since 1.0

timer.every(seconds: number, fn: function): integer

Calls fn repeatedly. An interval below 0.02 s is raised to 0.02.

ParameterTypeDescription
secondsnumberInterval. At least 0.02.
fnfunctionCalled each interval.
ReturnsDescription
integerA timer id.
lua
local id = timer.every(10, function() store.save() end)

timer.cancel#since 1.0

timer.cancel(id: integer): boolean

Stops a timer.

ParameterTypeDescription
idintegerA timer id.
ReturnsDescription
booleantrue when a timer was cancelled.
API 1.1 · source docs-src/api/timer.json