Skip to content

Script callbacks

A script can define up to five callbacks. All callbacks are optional. Use the preferred names in new scripts.

Callback order

Callback Arguments Use it for
Load assignedPlayerId Create script-wide values and write one startup log.
Init None Reset values that belong to one match.
Update deltaSeconds Read game data, make decisions, and submit bounded commands.
Render None Draw text, shapes, and world markers.
Shutdown None Release Lua state and write one final log.

Load runs when WololoLabs loads the script. A match might not be ready yet.

Init runs before the first update in each ready match. It can run again after a match ends and another match starts. Reset object IDs, timers, and flags here.

Update can run while the game is unavailable. Check for nil, 0, and empty arrays before you use a result.

Managed Lua updates run on a background worker by default. Native CalculatePathDistance searches are queued for the frame thread; the caller waits on its worker for the result. The rest of the Lua callback stays on the worker. Keep query counts bounded: sequential searches can each wait for another frame. Execution troubleshooting also offers synchronous main-thread Lua execution, which can stall rendering when a script does substantial work.

What each callback may do

The worker is on by default. With Execution troubleshooting set to run Lua on the main thread, Init, Update and Render all run on the frame thread instead, and Render draws directly.

Callback Runs on Game reads Commands Draw calls Settings
Load(assignedPlayerId) Frame thread, once per load or reload. Yes, but a match may not be running yet. Accepted, but there may be no match to send them in. No. Yes.
Init() Same thread as Update, just before the first Update of each match. Yes. Yes. No. Yes.
Update(deltaSeconds) Worker. deltaSeconds is the time since the last Update, including frames that passed while it ran. Yes. Yes; this is where commands belong. No: nothing is recorded outside Render. Yes.
Render() Worker, after each update pass (skipped when an Init or Update failed in it); also the frame thread, on frames when the worker is idle. Yes, but keep them cheap: it can run several times per Update. Don't: a second run sends the command again. Yes. While the worker is on, drawing is recorded and replayed, and screen queries such as WorldToScreen, GetZoom and IsOnScreen answer as if off screen; see Rendering. Yes.
Shutdown() Frame thread, before an unload or reload. Don't rely on game state. Allowed. Return false to stay loaded while your commands finish; WololoLabs asks again later. No. Yes.

Only one callback runs at a time: every callback holds the Lua lock, so Render on the frame thread never overlaps an Update on the worker. Values your callbacks share need no locking.

Update is not a simulation-tick or command-completion notification. Counting callbacks does not tell you when a multiplayer order has taken effect. Several independent requests may be admitted in one update; observe their receipts and game effects on later updates. See Timing, multiplayer, and script pacing.

Separate update work from drawing

Use Update to read data and decide what to do. Use Render to draw output. Store only Lua values, such as strings, numbers, colors, and positions, between the callbacks.

local label = "Waiting for a match"

function Update()
    local player = GetAssignedPlayer()
    label = player and player:GetPlayerName() or "Waiting for a match"
end

function Render()
    RenderTopRightText(label, 12, 12, 14, Color("#FFFFFFFF"), true)
end

A drawing view can be unavailable during loading or a state change. A drawing function can then produce no visible result. Do not use a screen query as game logic.

Require helper modules

Each script has its own require cache. A helper module runs once for each loaded script instance.

Use require only for files below the module entry folder. Return a table from each helper module. Keep callbacks in the entry file.

local format = require("format")

function Render()
    RenderTopRightText(format.label(), 12, 12)
end

Do not use load, loadfile, dofile, or package.path to load a script.

Handle errors

An error in Init, Update, or Render stops only that callback. WololoLabs records the script path and callback name, continues with other scripts, and tries Update and Render again later. A failed Init is not retried until the next match, so reset match state in a way that cannot fail. Check the Log Terminal for load or shutdown errors because they can have different reporting.

Handle expected missing game data with normal checks. Do not use pcall to hide a permanent script error. Log the state that explains a real failure.

Reload and shutdown

WololoLabs calls Shutdown before it unloads or replaces a script. Keep this callback short. Do not rely on the game state during shutdown.

Use the Reload button after you edit a script. Reload creates a new script state. Top-level values and require caches do not survive the reload.

Older callback names

Older name Current callback Note
onLoad Load Receives the assigned player ID.
onInit Load, not Init Despite its name, runs once when the script loads, like Load, and receives the assigned player ID. Used only when neither Load nor onLoad exists.
onTick Update Receives elapsed seconds.
onDraw Render No arguments.
onShutdown Shutdown No arguments.

Init has no older-name fallback. New scripts must use Load, Init, Update, Render, and Shutdown.