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.
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 that callback again later. 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 |
Used only when neither Load nor onLoad exists. Receives the assigned player ID. |
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.