Skip to content

timer functions

IllidanS4 edited this page Sep 25, 2018 · 4 revisions

ms(func, interval, ...)

Registers a function to be called after interval milliseconds. The function will be called in the main Lua thread. If additional arguments are provided, they will be passed to the function.

tick(func, interval, ...)

Registers a function to be called after interval server ticks. The function will be called in the main Lua thread. If additional arguments are provided, they will be passed to the function.

parallel([count, ] func, ...)

Calls func(...) but every count (default 100000) Lua VM instructions yields function(cont)tick(cont, 1)end from the Lua thread. If this is called inside async, it will register a function that resumes the coroutine. This creates the effect of running the code in parallel with the main thread; if the code takes too long to execute, it will be paused and scheduled on the next tick.

Non-Lua code cannot be interrupted this way, but most native functions in YALP can handle calling functions that may yield.

parallelreg([count, ] func, regfunc, ...)

Like parallel, but it yields regfunc.

sleep(ms)

Performs a blocking sleep on the current system thread for the given number of milliseconds. The sleep is active, i.e. it contains a loop that checks if the duration has elapsed or not. However, the loop is actually performed in Lua code, so it can be interrupted by hooks or paused via parallel.

This function should only be used as a substitute for CPU-intensive code, to test async and parallel. Use wait to pause the script asynchronously.

wait(ms, ...)

Analogous to coroutine.yield(timer.ms, ms, ...). Usually, this function should be called inside async, which handles the yield and registers the continuation, making the wait asynchronous.

waitticks(ticks, ...)

Analogous to coroutine.yield(timer.tick, ticks, ...) with semantics similar to wait.

Clone this wiki locally