dreamworkAPI
Ctrl K
GitHub
classDocs / Timer

Timer

classsharedmenusource
Object → Timer

The timer object.

Constructor

Timer(interval: ( number | nil ), repetitions_total: ( integer | nil ), name: ( string | nil )): Timer

Fields

NameTypeDescription
namestringThe internal name of the timer. Read-only.
stateTimer.stateThe current state of the timer. Read-only.
intervalnumberThe delay between repetitions of the timer in seconds.
repetition_indexintegerThe current repetition index of the timer. Read-only.
repetitions_totalintegerThe total amount of repetitions of the timer.
repetitions_leftintegerThe remaining amount of repetitions of the timer. Read-only.
time_totalnumberThe total running time of the timer in seconds. Read-only.
time_remainingnumberThe remaining running time of the timer in seconds. Read-only.
time_elapsednumberThe total elapsed time of the timer in seconds. Read-only.
time_leftnumberThe remaining time until the next run of timer callbacks in seconds, or the interval if the timer is stopped. Read-only.
start_timenumberThe start time of the timer in seconds, 0 if the timer is stopped. Read-only.

Methods

attachAttaches a handler called on every run of the timer, attaching the same handler twice is a no-op.
awaitWaits for the next run of the timer.
clearRemoves every handler of the timer, pending handlers of a running call are skipped.
detachDetaches a handler previously passed to attach or once.
isPausedChecks if the timer object is paused.
isRunningChecks if the timer object is running.
isStoppedChecks if the timer object is stopped.
onceAttaches a one-shot handler, detached right before the next run of the timer calls it.
pausePauses the timer object.
resumeResumes/unpauses the timer object.
startStarts/restarts the timer object.
stopStops the timer object.

#Timer:attach

sharedmenusource
function Timer:attach(handler: fun( timer: Timer ) | Hook | Event)

Attaches a handler called on every run of the timer, attaching the same handler twice is a no-op.

Handlers run in protected mode, one failing handler is reported and never stops the others.

Parameters
NameTypeDescription
handlerfun( timer: Timer ) | Hook | EventThe callback or callable object.

#Timer:await

sharedmenuasyncsource
async function Timer:await(): Timer

Waits for the next run of the timer.

Returns
TypeNameDescription
Timertimer

#Timer:clear

sharedmenusource
function Timer:clear()

Removes every handler of the timer, pending handlers of a running call are skipped.

#Timer:detach

sharedmenusource
function Timer:detach(handler: fun( timer: Timer ) | Hook | Event): boolean

Detaches a handler previously passed to attach or once.

Parameters
NameTypeDescription
handlerfun( timer: Timer ) | Hook | EventThe exact handler reference.
Returns
TypeNameDescription
booleanremovedtrue if the handler was attached.

#Timer:isPaused

sharedmenunodiscardsource
function Timer:isPaused(): boolean

Checks if the timer object is paused.

Returns
TypeNameDescription
booleanis_pausedReturns true if the timer is paused, otherwise false.

#Timer:isRunning

sharedmenunodiscardsource
function Timer:isRunning(): boolean

Checks if the timer object is running.

Returns
TypeNameDescription
booleanis_runningReturns true if the timer is running, otherwise false.

#Timer:isStopped

sharedmenunodiscardsource
function Timer:isStopped(): boolean

Checks if the timer object is stopped.

Returns
TypeNameDescription
booleanis_stoppedReturns true if the timer is stopped, otherwise false.

#Timer:once

sharedmenusource
function Timer:once(handler: fun( timer: Timer ) | Hook | Event)

Attaches a one-shot handler, detached right before the next run of the timer calls it.

Parameters
NameTypeDescription
handlerfun( timer: Timer ) | Hook | EventThe callback or callable object.

#Timer:pause

sharedmenusource
function Timer:pause()

Pauses the timer object.

#Timer:resume

sharedmenusource
function Timer:resume()

Resumes/unpauses the timer object.

#Timer:start

sharedmenusource
function Timer:start()

Starts/restarts the timer object.

#Timer:stop

sharedmenusource
function Timer:stop()

Stops the timer object.

Generated from the dreamwork meta branch.