- Documentation
- Timers
Category
Timers
All Lua functions and events in the Timers category, on the server and the client.
Shared functions 16
asyncRuns a function as a task (coroutine). The code in the task runs immediately until its first wait (sleep,await,waitForEvent). Then it yields and the server and the game keep running. When the wait is over, the task continues from where it stopped. This lets you write steps spread over time (a countdown, a database query, an HTTP response, waiting for a player) one after another, without nested callbacks and timers.awaitWaits for a result inside anasynctask. It takes two forms. The first is a starter function: it receivesresumeand starts something that ends in a callback (adbQueryquery,fetchRemote, a timer). When the callback callsresume(...),awaitreturns the same values. The second form is another task fromasync:awaitwaits until it ends and returns its results, and if that task failed, it re-throws the error (catch it withpcall).getReturns the state of a task fromTask Status async:"running"(waiting or working),"done"(finished) or"failed"(error). After the state it returns the values returned by the task function or, for"failed", the error message.getReturns the time until the timer's next call, the number of remaining repeats and the interval.Timer Details getReturns a description of the timer as a table:Timer Info remaining,repeats,interval,pausedandresource.getReturns the active timers of the calling resource. With an argument, only those whose interval does not exceed the given number of ms.Timers isChecks whether a value is a task returned byTask async.isChecks whether a value is an active timer. A one-shot timer stops being active after it fires.Timer isChecks whether a timer is paused byTimer Paused setTimerPaused.killStops a timer permanently. Its function will not be called any more.Timer resetRestarts counting the timer's interval from this moment.Timer setCalls a function after a given time, once, several times or forever.Timer setSets the time until the timer's next call without changing its interval.Timer Delay setPauses or resumes a timer. The remaining time is kept.Timer Paused sleepPauses anasynctask for the given time. Meanwhile other scripts, the server and the game run normally.sleep(0)waits until the next server frame (the same assetTimerwith interval 0).waitPauses anFor Event asynctask until an event happens. Returns the event'ssourceelement and its arguments. With a time limit it returnsfalseif the event did not happen in time. The handler and the limit timer are removed when the wait ends.