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)
| Field | Type |
|---|---|
| Signature | (fn: () → ()) → number |
| Returns | number — task id, pass to removeThread(id) to abort it later |
| Async | no — 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)
| Field | Type |
|---|---|
| Signature | (threadId: number) → boolean |
| Returns | boolean — true if the id matched a live task; false when it was already done or never registered |
| Async | no |
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)
| Field | Type |
|---|---|
| Signature | (ms: number) → () |
| Returns | nothing |
| Async | yes — 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