Lua ScriptingIntermediate

Scene scripts, variables, and storage

Coordinate a level with scene APIs, runtime objects, scene variables, audio, and persistent storage.

Scene scripts

Assign one project script in Scene Settings. It receives the same init, update, and destroy lifecycle but runs once for the scene rather than once per object.

Lookup and physics

Scene scripts can call getObjectByName(name), getObjectsByNamePrefix(prefix), getObject(id), getObjectsByType(type), getGravity(), and setGravity(x,y,z).

Scene variables

scene.getVar(name) reads number, string, boolean, or object-reference values. scene.setVar(name,value) updates primitive values for the running scene.

Runtime objects

scene.createObject(type, options) creates a simulation-only object and returns its object API. scene.destroyObject(id) and scene.destroyObjectByRef(object) can destroy runtime-created objects. Authored scene objects cannot be deleted through these runtime methods.

Audio and scene transitions

Use scene.playSound, scene.playMusic, scene.stopMusic, scene.setMusicVolume, and scene.setSfxVolume. scene.loadScene(idOrName) queues a transition to another scene included in the current game.

Game storage

local highScore = gameStorage.get("highScore") or 0
gameStorage.set("highScore", math.max(highScore, 250))
gameStorage.remove("temporaryValue")
-- gameStorage.clear() removes every value for this game.