Function
sleep
Pauses an async task for the given time. Meanwhile other scripts, the server and the game run normally. sleep(0) waits until the next server frame (the same as setTimer with interval 0).
Syntax
bool sleep(int ms)Arguments
msint- Time in milliseconds.
Returns
true after the time has passed.
Example
async(function()
outputChatBox("Za 2 sekundy pojawi się napis")
sleep(2000)
outputChatBox("Gotowe")
end)
Notes
Only inside a task. Outside async it raises an error instead of freezing the whole server.
See also
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).setTimerCalls a function after a given time, once, several times or forever.