Skip to main content

Threading

Background threads driven from Lua. Unlike the original Lucifer runtime, threads share the script's globals — you can read / mutate value from anywhere.

local value = 0

local threadId = runThread(function()
value = 5
end)

removeThread(threadId) -- stop a specific thread

sleep(ms) yields the current coroutine. Pair it with pathfinding() polls or connected() waits when you need to hand the scheduler a slice.

Globals

runThread(fn)

FieldType
Signature(fn: () → ()) → number
Returnsnumber — task id, pass to removeThread(id) to abort it later
Asyncno — returns the id immediately, the function runs on a detached tokio task

Spawn fn as a fire-and-forget tokio task. The function runs detached — return values are discarded; errors are swallowed silently. Use getLogs() / print() to surface progress.

local id = runThread(function()
sleep(60000)
print("woke up")
end)

removeThread(threadId)

FieldType
Signature(threadId: number) → boolean
Returnsbooleantrue if the id matched a live task; false when it was already done or never registered
Asyncno

Cooperatively cancel + abort the task with the given id (a value previously returned by runThread). Idempotent — calling it twice on the same id returns false the second time.

local id = runThread(function() sleep(60000) end)
removeThread(id) -- true
removeThread(id) -- false (already gone)

sleep(ms)

FieldType
Signature(ms: number) → ()
Returnsnothing
Asyncyes — yields the script for ms milliseconds

Cooperative — other bots and packet handlers keep running. Don't call inside synchronous event handlers.

sleep(1500) -- 1.5s

Run across every connected bot

for i, b in ipairs(getClients()) do
runThread(function()
-- per-bot work, all run concurrently
b:warp("MYWORLD")
end)
end