Lua ScriptingBeginner

Lua scripting overview

Use lifecycle callbacks, input, gameObject, scene, and gameStorage safely.

Object-script lifecycle

function init()
    -- Runs once when simulation starts.
end

function update(deltaTime)
    -- Runs once per simulation frame.
end

function destroy()
    -- Runs when simulation stops.
end

Optional callbacks include onCollisionEnter, onCollisionExit, onTriggerEnter, onTriggerExit, and onClick for scripted GUI objects.

Global APIs

  • gameObject: the object the script is attached to.
  • scene: scene transitions and the active camera for object scripts; the full scene API for scene scripts.
  • input: shared keyboard, pointer, and mobile control state.
  • gameStorage: values persisted for the current game in the browser.

Input fields

The shared input bus includes moveForward, moveBackward, moveLeft, moveRight, lookUp, lookDown, lookLeft, lookRight, jump, and primaryFire.

Missing values

Bindings return Lua nil when nothing is found. Check a returned object before calling methods on it.