Overview
Timers
Schedule one-shot or repeating callbacks with setTimeout and setInterval.
console
Log, warn, error, and assert output to the script console.
Events
addEventListener for ticks, input, and engine events.
script
Metadata about the running script - name, version, author.
Timers
Standard browser-style timer API. IDs returned bysetTimeout and
setInterval are independent - pass the right ID to the right clear function.
setTimeout
callback once after ms milliseconds. Returns a timer ID.
setInterval
callback repeatedly every ms milliseconds. Returns a timer ID.
clearTimeout / clearInterval
Timers do not survive a reload: every timer belonging to a script is
dropped when it unloads, so a forgotten
setInterval cannot pile up across
hot reloads. Clearing them in onUnload is still good hygiene, not damage
control.console
Objects print as objects
Values are formatted by an inspector, not bytoString(), so structures are
readable without wrapping everything in JSON.stringify:
[Object]), long arrays and strings are
truncated with a note, and cycles print as [Circular] instead of hanging.
Getters are shown as
[Getter] and never invoked. Reading a property off
an entity is a memory read, and logging must not have side effects - so
console.log(player) will not silently read every field of the entity.Extras
%s %d %i %f %o %O %j %%.
Events
Events use the standardaddEventListener API. Everything a browser gives you
works here - once, signal, preventDefault, custom EventTargets - see
Web APIs.
addEventListener
AbortController:
A listener that throws does not take the script down: the error is reported
through the
error event and the remaining listeners still run.on / once / off (legacy)
on returns a numeric ID for
off. Old event names ("OnKeyDown", "OnMouseMove", …) keep working and
resolve to the same events as the modern names.
Built-in events
Input events carry the fields you would expect in a browser:
on() API
passes for the same events.
"render"
Fires every frame when the overlay is being drawn. All Render module
calls must happen inside this callback - drawing outside of it will cause
flickering or missing visuals because the frame may have already been
submitted.
"tick"
Fires on the script loop, which targets 128 Hz independently of the
server tickrate and of your framerate. The primary place for logic -
entity reads, state machines, calculations. Do not draw here - use
"render" for that.
"OnMouseMove"
"OnMouseClick"
"OnMouseScroll"
"OnKeyDown" / "OnKeyUp"
onUnload
Script cleanup is handled by exporting a function namedonUnload.
It is called once when the script is about to be unloaded or reloaded.
unload event, fired just before onUnload is called.
Use whichever fits - the event works with AbortController cleanup, the export
does not need a listener:
Execution budget
Script code runs on one shared worker thread, so a listener that never returns would freeze every script at once. Two thresholds guard against that:
Only JavaScript time counts. A slow native call - reading a big file,
scanning a whole module, an FFI call into blocking code - pauses the clock, so
you are never punished for the host being slow:
script
Thescript object exposes metadata about the currently running script.
All fields are readonly.