Skip to content

timer

Schedules functions on the game loop.

Source: src/Moongate.Scripting/Modules/TimerModule.cs

timer.after(seconds, fn) -> string

Runs fn once after the given seconds, which must be positive. Returns a handle for cancel.

ParameterTypeDefault
secondsnumber
fnfunction

Returns string.

timer.cancel(handle) -> boolean

Cancels a timer by handle. Returns false when no such timer is pending.

ParameterTypeDefault
handlestring

Returns boolean.

timer.every(seconds, fn) -> string

Runs fn every given seconds, a positive interval, until cancelled. Returns a handle for cancel.

A repeating timer whose function waits, cancelled by a one-shot timer:

local pulse = timer.every(30, function()
log.info("Pulse")
wait(2)
log.info("Pulse resumed")
end)
timer.after(95, function()
log.info("Pulse cancelled: {Cancelled}", timer.cancel(pulse))
end)
ParameterTypeDefault
secondsnumber
fnfunction

Returns string.

Made with ❤️ by Tom

Buy me a coffee