Metroidvania Studio Docs1.3.2GitHub

Lua API reference

Scripts use a restricted Lua 5.2 interpreter and studio.api_version == 1. The automation API version is separate from the application's version and the map JSON format version.

Inspect the input map

Room summaries include roomId, name, x, y, width, height, visible, locked, foregroundCount, backgroundCount, objectCount, properties, and objects. Object summaries include objectId, definitionId, layer, x, y, width, and height.

These are detached snapshots of the map before the script started. Changing a returned table does not edit the map. Queued operations do not appear in later snapshot queries. Keep returned IDs and calculated positions in local variables while constructing a batch.

Edit the map

Each method accepts exactly one table. The table fields match the common automation API; the method name supplies op automatically.

Lua methodRequired fieldsCommon optional fields
studio.room.addx, y, width, heightid, name
studio.room.updateroomIdname, visible
studio.room.moveroomId, x, y
studio.room.resizeroomId, width, heightx, y, crop, keepLocalContents
studio.room.rotateroomIdclockwise
studio.room.duplicateroomId, x, yid, name
studio.room.deleteroomId
studio.tiles.paintroomId, layer, cellsmaterialId, groupId
studio.tiles.eraseroomId, layer, cellsgroupId
studio.tiles.rectangleroomId, layer, x, y, width, heightmaterialId, shape, erase, groupId
studio.tiles.fillroomId, layer, x, ymaterialId, shape, erase, groupId
studio.properties.setvaluesroomId
studio.camera.setppu, width, height
studio.object.addroomId, definitionId, layer, x, yid, width, height, groupId, properties
studio.object.updateroomId, objectIdx, y, width, height, rotation, scaleX, scaleY, definitionId, properties
studio.object.deleteroomId, objectId
studio.renamename

studio.room.add, studio.room.duplicate, and studio.object.add return the created ID. Pass explicit IDs when another script or external system needs stable names. Otherwise the runner assigns IDs without colliding with existing rooms or objects.

studio.apply { op = "room.add", ... } accepts the common operation form directly. It has the same limits and validation as named methods. Use studio.rename { name = "World" } for the document.update operation.

Tile layers are "foreground" and "background". Object layers are "entities", "triggers", "foregroundDecals", and "backgroundDecals". A cell is { x = 0, y = 0, shape = "solid" }; shape can also be "bottomLeft", "bottomRight", "topLeft", or "topRight". Paint defaults to material "terrain" and shape "solid".

Array fields use consecutive integer keys starting at 1. Room/world coordinates and tile cells are integers. Objects support fractional local coordinates. Each resource uses a catalog ID such as materialId or definitionId, not a filesystem path.

Use strings for property values. To remove a property, pass studio.null; assigning Lua nil removes the table entry before the operation reaches the API.

lua
studio.properties.set {
    roomId = "entry",
    values = { region = "Garden", temporary = studio.null }
}

Resize preserves content by default. crop = true explicitly permits cropping. Overlapping rooms, invalid IDs, out-of-bounds painting, and edits to protected content fail the whole batch.

Available Lua functions

Lua control flow, local functions, tables, arithmetic, concatenation, and comparisons are available. Basic functions include assert, error, ipairs, pairs, next, select, tonumber, tostring, and type.

String helpers use the interpreter's UTF-16 text representation. Use ASCII when indexing by individual character positions. Unicode names and property values are preserved when passed as whole strings.

File I/O, networking, processes, modules, dynamic code loading, host object access, metatables, debug functions, coroutine APIs, and custom error-catching functions are unavailable. See execution limits before processing large maps.

Metroidvania Studio 1.3.2 · Offline guides are available through Help → Documentation in the studio.