engine
The `engine` global's Luau implementation. Exposes `engine.mode` (edit vs play), `engine.onModeChange(callback)` subscription registry, and the mode-flip orchestration that fires the canonical onModeChange dispatch through `ENGINE_MODE_WATCHERS`.
modules.api.engine.engine
The engine global's Luau implementation. Exposes engine.mode (edit
vs play), engine.onModeChange(callback) subscription registry, and
the mode-flip orchestration that fires the canonical onModeChange
dispatch through ENGINE_MODE_WATCHERS.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2global engine module Engine Process-level engine state surface. Read-only boot profile and read-write engine mode. Both exposed as computed properties via metatable __index / __newindex — never call them as methods. Usage: if engine.profile == "editor" then ... end engine.mode = "play" engine.setMode("play", { strict = false }) Implemented as a thin Luau wrapper over internal FFI: engine.profile → __engineSettings.get("profile") engine.mode → __mode.get() / __mode.set(value) engine.setMode → __mode.set(value, strict) engine.paused → __pause.get() / __pause.set(value) engine.timeScale → __timescale.get() / __timescale.set(value) engine.timeScaleOwner → who the rate answers to (hold, or last writer) engine.gameplayReady → __gameplay.ready() `engine.mode = X` is load-bearing — the setter owns the mode-flip side effects so any path that changes mode behaves identically: edit → play: drain pending edit-mode marks into the dirty overlay (so wld.edit() can reassemble the user's authored state) BEFORE flipping `__mode`. Never writes canonical scene.json. play → edit: flip `__mode` first, then reload the active non-additive layer so the dirty overlay reapplies + play-mode runtime mutations are discarded. Toolbox wrappers (`wld.play()` / `wld.edit()`) are thin pass-throughs — they MUST NOT carry side-effect logic. If a future caller writes `engine.mode = "play"` directly (or via a different toolbox tool), the same side effects fire. Putting drain/reload on the toolbox alone would let a direct assignment leave the scene in a half-applied state. See `man engine` for the full surface and side effects. require modules/engine
watchPlaySessions( ) → void
recordWatcher(registry: string, id: any) → any
The caller is the first frame above this module's own that is Luau code, past the native dispatcher a `typed` function's argument check runs the registering function through. It is the same frame at every optimization level the module compiles at.
| arg | type | description |
|---|---|---|
| registry | string | |
| id | any |
forgetWatcher(registry: string, id: number, removed: boolean) → boolean
The record of who registered a watcher goes with the watcher: an id the registry no longer holds names nobody, so its source line leaves the record whatever the removal answered. The removal is handed the source line first, and a scripting baseline that puts the watcher back hands it back (`M.resetScriptingState`).
| arg | type | description |
|---|---|---|
| registry | string | |
| id | number | |
| removed | boolean |
watcherSources( ) →
Who registered each watcher still standing, by registry: `modeWatchers`, `pauseWatchers`, `deviceRebuiltWatchers`, `memoryPressureWatchers`, `backgroundWatchers`, `worldReadyWatchers` and `worldUnloadingWatchers`, each a map from watcher id to the source and line that registered it. A watcher registered before this module loaded is absent. What a reading of the registry counts names when it finds a watcher more than it began with.
examples
for id, at in pairs(engine.watcherSources().modeWatchers) do print(id, at) end
onModeChange(callback: (string, string) → void
| arg | type | description |
|---|---|---|
| callback | (string, string |
onPauseChange(callback: (boolean, boolean) → void
Register a callback that fires synchronously whenever the gameplay pause flag flips via an explicit `engine.paused` write. Callback receives `(newPaused, oldPaused)` as booleans. Returns a watcher id. Pause is independent of `engine.mode`: pausing play mode returns the editor authoring surface (free camera + EditorOnly entities) over the frozen play world, and resuming hides it again. Mode-driven pause resets (the edit=paused / play=running defaults applied on a mode flip) are delivered through `onModeChange`, not this hook.
| arg | type | description |
|---|---|---|
| callback | (boolean, boolean | Function invoked as `(newPaused: boolean, oldPaused: boolean)`. |
examples
local id = engine.onPauseChange(function(paused)
print(paused and "frozen" or "running")
end)
onDeviceRebuilt(callback: (number) → void
Register a callback that fires after the engine has answered a lost render device by building another one. The callback receives the new device generation — a number that counts the devices this session has run on, and moves exactly once per rebuild. Returns a watcher id. A device is lost when the driver resets, when the GPU is taken away, or when a browser reclaims a WebGPU context. Everything the engine can re-derive by itself it does: meshes, materials, shaders, render passes and the UI are all back on the new device before this fires. What it cannot re-derive is what YOUR content made and only the GPU held — a texture uploaded from pixels a script computed, a compute buffer it filled, a render target it created. Make those again here. Content that owns no GPU resource of its own needs no subscriber: asset handles re-materialise on their next use.
| arg | type | description |
|---|---|---|
| callback | (number | Function invoked as `(generation: number)`. |
examples
engine.onDeviceRebuilt(function(generation)
-- the noise field lived only on the GPU, so it is computed again
print("upload the noise field again for device generation", generation)end)
offDeviceRebuilt(id: number) → boolean
Remove an `engine.onDeviceRebuilt` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none — already removed, or never registered.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onDeviceRebuilt`. |
examples
local id = engine.onDeviceRebuilt(function() end)
engine.offDeviceRebuilt(id)
onMemoryPressure(callback: (string, string) → void
Register a callback that fires when the system says it is short of memory, after the engine has released what that level of pressure releases. The callback receives the level (`"normal"`, `"moderate"`, `"low"` or `"critical"`) and who reported it: `onTrimMemory(<level>)` for Android's report, `script` for `renderer.signalMemoryPressure`. Returns a watcher id. The engine frees what it can rebuild by itself: mip levels the frame does not sample, render-target storage nothing is drawing into, and from `"critical"` half the texture budget. What it cannot free is what YOUR content keeps: a cache of generated meshes, a table of decoded audio, pixels kept for a later upload. Drop those here and build them again when they are next needed. A level stands for a minute after the last report, and `renderer.memoryPressure()` reads the level in force and what the engine released.
| arg | type | description |
|---|---|---|
| callback | (string, string | Function invoked as `(level: string, source: string)`. |
examples
engine.onMemoryPressure(function(level, source)
if level ~= "normal" then
decodedClips = {} -- decoded again on next playend
end)
offMemoryPressure(id: number) → boolean
Remove an `engine.onMemoryPressure` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none: already removed, or never registered.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onMemoryPressure`. |
examples
local id = engine.onMemoryPressure(function() end)
engine.offMemoryPressure(id)
onBackgroundChange(callback: (boolean, string) → void
Register a callback that fires when the app goes into the background and again when it comes back. The callback receives whether the app is in the background now and who reported it: `"android"` (the engine's activity was stopped or started), `"window"` (the desktop window was minimized or restored), `"page"` (the browser tab was hidden or shown) or `"script"` (`engine.signalBackground`). Returns a watcher id. The platform may end the process at any moment once the app is in the background, with no further frame: Android ends a stopped app to take its memory back, and a browser discards a hidden tab. Save what the player would lose here: write it to `runtime_data`, which the next session reads back. The world's `/source` writes are kept already: each is recorded on the device as it is made and reaches the world when a session next connects. The engine writes what it keeps across launches before this fires. While the app is in the background the engine keeps running, more slowly, and draws nothing.
| arg | type | description |
|---|---|---|
| callback | (boolean, string | Function invoked as `(inBackground: boolean, source: string)`. |
examples
engine.onBackgroundChange(function(inBackground, source)
if inBackground then
runtime_data.player(runtime_data.localId()).set("save/checkpoint", { level = 3, coins = 120 })end
end)
offBackgroundChange(id: number) → boolean
Remove an `engine.onBackgroundChange` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none: already removed, or never registered.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onBackgroundChange`. |
examples
local id = engine.onBackgroundChange(function() end)
engine.offBackgroundChange(id)
inBackground( ) → boolean
Whether the app is in the background now: the engine's Android activity is stopped, the desktop window is minimized, or the browser tab is hidden. `engine.onBackgroundChange` fires on each change.
examples
if engine.inBackground() then return end -- nobody sees this frame
signalBackground(inBackground: boolean) → boolean
Report the app going into the background (`true`) or coming back (`false`) the way the platform does, so the path content takes on a real backgrounding can be run on demand: the engine writes what it keeps across launches and `engine.onBackgroundChange` subscribers hear it with source `"script"` on the next frame. The live world session reacts as it does to a hidden browser tab or a minimized window. A later report from the platform that changes where the app is stands over it. Returns whether the report changed what `engine.inBackground()` answers.
| arg | type | description |
|---|---|---|
| inBackground | boolean | Whether the app goes into the background. |
examples
engine.signalBackground(true) -- subscribers save on the next frame
engine.signalBackground(false)
onWorldReady(callback: () → void
Register a callback fired (no args) when the bound world's content has been synced into the VFS, the packages the world installs have materialized, and the world is ready to load. This is the race-free, user-space hook that drives the whole world-VM lifecycle: the builtin world-entrypoint loader subscribes to it and, when it fires, `loadstring(vfs.read(...))`s `/source/.world_entrypoint.luau` and runs its `onWorldLoad` — exactly the way a scene entrypoint loads. The trusted VM fires this (via `world.markReady()`) ONLY once the bytes are in the VFS, so a subscriber never sees a half-synced world. Returns a watcher id.
| arg | type | description |
|---|---|---|
| callback | ( | Function invoked with no arguments. |
onWorldUnloading(callback: () → void
Symmetric teardown of `engine.onWorldReady`: register a callback fired (no args) when the bound world is unbinding/swapping out. The builtin loader runs the world entrypoint's `onWorldUnload` here, so the world entrypoint has the same load/unload parity a scene entrypoint has. Returns a watcher id.
| arg | type | description |
|---|---|---|
| callback | ( | Function invoked with no arguments. |
offModeChange(id: number) → boolean
Remove an `engine.onModeChange` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none — already removed, or never registered.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onModeChange`. |
examples
local id = engine.onModeChange(function() end)
engine.offModeChange(id)
offWorldReady(id: number) → boolean
Remove an `engine.onWorldReady` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onWorldReady`. |
offWorldUnloading(id: number) → boolean
Remove an `engine.onWorldUnloading` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onWorldUnloading`. |
offPauseChange(id: number) → boolean
Remove an `engine.onPauseChange` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onPauseChange`. |
isObjectCapture(captured: any) → boolean
Internal: whether a captured value stands for an object.
| arg | type | description |
|---|---|---|
| captured | any |
answersAlive(obj: any) → boolean
Internal: what an object answers for itself about whether it still addresses anything: `true`, `false`, or nil for one that does not answer. A handle answers `alive` for itself when it carries the identity of what it addresses, or answers through its class. A namespace whose `alive` takes a handle as its argument carries neither, and is not asked.
| arg | type | description |
|---|---|---|
| obj | any |
standsAsItIs(captured: any) → boolean
Internal: whether a capture is one a restore leaves as it stands: a value in use, or an engine record.
| arg | type | description |
|---|---|---|
| captured | any |
executingModules( ) → void
Internal: the modules with a frame on the stack right now, by chunk name, with and without the `.__init` a module body's chunk carries.
carriesFunction(t: { [any]: any }) → boolean
Internal: whether a table carries a function among its own fields. A table whose fields are its methods is an object whether or not a metatable says so: what it addresses is bound in those closures — a buffer handle's `alive` and `destroy` close over the allocation they name — and a copy of the closures addresses nothing of its own.
| arg | type | description |
|---|---|---|
| t | { [any]: any } |
captureValue(value: any, seen: { [any]: any }) → any
Internal: a capture of `value`. `seen` maps each table already captured to its capture, so a graph that shares a table captures to one that shares a capture, and a cycle terminates. Keys are carried by reference. A table used as a key IS an identity, and a copy of one addresses nothing that was filed under it.
| arg | type | description |
|---|---|---|
| value | any | |
| seen | { [any]: any } |
reminted(value: any) → any
Internal: `value`, or the id the engine now uses for it.
| arg | type | description |
|---|---|---|
| value | any |
standsInAlready(live: any, standing: any) → boolean
Internal: whether `live`, the value a slot holds now, already stands in for the gone object `standing` was found for.
| arg | type | description |
|---|---|---|
| live | any | |
| standing | any |
objectGone(obj: any) → boolean
Internal: whether an object the reading holds has since lost what it addressed. A handle that answers `alive` says so itself; the caller's reading answers for the rest; every other object is taken to stand.
| arg | type | description |
|---|---|---|
| obj | any |
successorOf(obj: any) → any
Internal: the live object standing in for `obj`, which has gone, or nil when nothing stands in for it. Asked once per object per restore.
| arg | type | description |
|---|---|---|
| obj | any |
describeGone(obj: any) → string
Internal: a gone object as a restore names it — its kind and the id it carries where those are plain values, else the fields it holds.
| arg | type | description |
|---|---|---|
| obj | any |
plain(v: any) → string
| arg | type | description |
|---|---|---|
| v | any |
holdsGoneObject(captured: any, memo: { [any]: boolean }) → boolean
Internal: whether `captured` holds, anywhere in what it recorded, an object that has since gone. `memo` carries the answer per capture, and a capture being walked answers false to a cycle back into it. The object found gone is left in `lastGoneObject`.
| arg | type | description |
|---|---|---|
| captured | any | |
| memo | { [any]: boolean } |
replacedSince(captured: any) → boolean
Internal: whether the object `captured` recorded has gone since the reading was taken and a live object stands in for it now. A slot still holding that gone object is one the module stopped using: a module that let a buffer go with a lost device and made it again keeps the new handle wherever it keeps it now, and the slot the reading is refilled into takes that one.
| arg | type | description |
|---|---|---|
| captured | any |
materialise(captured: any, built: { [any]: any }) → any
Internal: the value a live slot should hold for `captured` — the object itself for an object capture, a fresh copy for data, so one reading stays good for every later restore rather than being handed to the state it is there to correct. `built` keeps the sharing the capture recorded.
| arg | type | description |
|---|---|---|
| captured | any | |
| built | { [any]: any } |
engineRecord(record: { [any]: any }) → void
Declare `record` an engine record: a table a subsystem keeps as its own account of what the engine holds — the renderer's registry of live features, its capture views — and puts back through its own reset. `engine.snapshotModuleState` neither copies nor walks it, and `engine.restoreModuleState` leaves it as that reset left it, so a module restore never seats a record back around what the reset did: a feature a suite destroyed stays destroyed, and one it made again under its identity stays the one the renderer ticks.
| arg | type | description |
|---|---|---|
| record | { [any]: any } | The table. |
examples
engine.engineRecord(activeFeatures)
newSlice( ) → void
A function that yields one frame once the slice it was made at has run its length, and does nothing for a caller that cannot yield.
snapshotModuleState( ) →
Read the state every cached module holds — the upvalues of the closures it hands back — and answer with it, so `engine.restoreModuleState` can put exactly that back later. Take it once, before the work whose changes are to be undone. Data is copied, so a table a module goes on mutating does not change what was read; an object — a table carrying a metatable or methods of its own — is kept by reference and its fields copied, so restoring returns the object every other holder is still attached to rather than a lookalike that answers none of its methods. A module with a frame on the stack while the reading is taken — the caller, and whatever called it — is mid-operation, and what it holds is left out: neither copied here nor written back by the restore, however another module reaches it. Called from a coroutine that can yield, the walk gives the frame back every few milliseconds, so the engine keeps stepping through a reading that takes seconds. pass A snapshot value to hand to `engine.restoreModuleState`. captured, the require cache as `{ key, value }` pairs, how many modules it covers, how many were left out for executing, and the count of values that could not be read.
examples
local snap = engine.snapshotModuleState()
eachFunction(root: any, visit: (any) → void
| arg | type | description |
|---|---|---|
| root | any | |
| visit | (any |
chunkOf(fn: any) → string
The module a function belongs to is the chunk it was compiled in, named the way `executingModules` names a frame, whatever table the walk reached it through: a class held in one module's local is read under the module that wrote it, and an executing module's closures are told apart from the walk that found them.
| arg | type | description |
|---|---|---|
| fn | any |
readFunction(fn: any) → void
| arg | type | description |
|---|---|---|
| fn | any |
readUpvalues(key: string?, fn: any) → void
| arg | type | description |
|---|---|---|
| key | string? | |
| fn | any |
markHeld(value: any) → void
| arg | type | description |
|---|---|---|
| value | any |
markUpvalues(fn: any) → void
| arg | type | description |
|---|---|---|
| fn | any |
restoreModuleState(snapshot: { [string]: any }, options: { remint: { [string]: string }?, gone: ((any) →
Put every module's state back to what `engine.snapshotModuleState` read. A table is refilled in place, so a closure holding it sees the restored contents, and the upvalue is pointed back at it, so a module that assigned its local a new table is reading the restored one again. The same snapshot restores to the same state however many times it is used, so one reading taken before a run puts every later point in that run back to it. A value whose reading names an object the engine no longer holds — a buffer whose storage was destroyed since, answering `alive` false — is left as it stands: what it remembered cannot be given back to it, and what it holds now is what it went on to make. The module holding it is left whole, because what it remembers beside that object — the count it sized the object for, the flag that says it made one — is the state of the object it now holds instead; it is counted under `stale`. A data table naming a gone object in one of its fields is a registry, and is refilled around that field. Called from a coroutine that can yield, the restore gives the frame back every few milliseconds. pass Every reachable upvalue holds what the snapshot recorded, with each id the engine re-minted since replaced by the id it now uses. uses for the same thing — a render feature's guid after the feature was made again under its identity. `gone` answers whether a value the reading holds names something the engine no longer holds — a record carrying a render feature's guid when no feature carries it now; a handle answering `alive` false is known without it. `successor` answers, for an object that has gone, the live object standing in for it — the handle under a buffer's name after the buffer was made again under it — and the reading is put back holding that one, its own fields left as they are. A handle that already answered `alive` false when the reading was taken is the module's own record of something gone before it, and is put back as it is. `same` answers whether a value a module holds now already stands in for the gone object a successor was found for — the module's own live handle to the buffer made again under the name — and such a value is kept, the successor released. `only` names the modules to put back, by module name, and every other module's reading is left untouched — a second pass over the modules an earlier one left as they stood, once what stands in for the objects they named exists. how many values were written, how many the engine would not write, how many require-cache entries were put back to the module they held, how many modules hold a value left as it stood because its reading names something the engine no longer holds, and those modules by name, each with the gone object the reading named; then how many modules hold a value whose restore raised, and those by name with the error. A value whose restore raises is counted and passed over, and the rest of the reading is put back.
| arg | type | description |
|---|---|---|
| snapshot | { [string]: any } | |
| options | { remint: { [string]: string }?, gone: ((any | `remint` maps an id the reading holds to the id the engine now |
examples
engine.restoreModuleState(snap)
engine.restoreModuleState(snap, { remint = { [oldGuid] = newGuid } })markInUse(captured: any) → void
What an executing module holds is in use however it is reached: the runner's results table is its own field and also an upvalue of modules that only required the runner, and putting it back through one of those would empty it just the same. Every table reachable from an executing module's values is marked before anything is restored, so the restore passes over it from every path.
| arg | type | description |
|---|---|---|
| captured | any |
putBack(entry: any) → void
| arg | type | description |
|---|---|---|
| entry | any |
timeScaleActor( ) → void
The agent this call is attributed to, which labels a hold or a write that states no key of its own so a reader is told somebody either way. The identity is the one the VFS records a play-shadow write under, so the two surfaces name the same caller.
timeScaleStatedOwner(options: TimeScaleHoldOptions?) → string
The key a caller states this hold under, if it states one. An exclusive hold is taken for that key and a later hold presents it to be admitted, so it is read from what the caller said rather than from anything resolved for it. A blank key is refused the way `engine.releaseTimeScale` refuses one, since the two calls have to name the same hold to find it.
| arg | type | description |
|---|---|---|
| options | TimeScaleHoldOptions? |
timeScaleHoldKey(stated: string?) → void
| arg | type | description |
|---|---|---|
| stated | string? |
timeScaleTop( ) → TimeScaleHold
The innermost hold, which is the one naming the rate in force.
timeScaleExclusive( ) → TimeScaleHold
The exclusive hold standing over the whole stack, if one stands. At most one can: taking a second from another key is refused, and the same key's nested holds are the only other entries the stack can carry while it does.
timeScaleLabel(standing: TimeScaleHold) → string
How a refusal names the caller already holding the rate, so the one refused reads who exists rather than guessing why its own rate did not take.
| arg | type | description |
|---|---|---|
| standing | TimeScaleHold |
timeScaleOwnerRecord( ) → TimeScaleOwner
Who the rate answers to right now: the hold naming it while one stands, and otherwise whoever wrote it outright last. `scale` is read from the rate in force rather than from what the owner asked for, so the record and `engine.timeScale` are one answer. Each read builds its own record, so a reader holding one cannot edit what the next reader is told.
effectiveTimeScale( ) → number
The rate in force once the stack has changed: the innermost hold's, or the rate that stood before the outermost when the stack has emptied.
applyTimeScale(scale: number) → void
Put a rate in force and tell every subscriber, from one place, so a hold, a release and an outright write all announce themselves the same way. The value is in force before the subscribers run, so one reading `engine.timeScale` inside its callback reads the rate it was told about.
| arg | type | description |
|---|---|---|
| scale | number |
timeScaleHeldRefusal(standing: TimeScaleHold) → string
The refusal a write meets while a hold stands, naming the holder and the two ways out of it.
| arg | type | description |
|---|---|---|
| standing | TimeScaleHold |
holdTimeScale(scale: number, options: TimeScaleHoldOptions?) →
Run the simulation at `scale` for as long as the hold stands, and process, so a rate one agent sets is the rate every other agent's entities and measurements run at; a hold records who set it and refuses a plain `engine.timeScale` write from anywhere else while it stands, so the rate cannot move under a measurement without the measurement hearing about it. Holds nest: the innermost names the rate, and the rate that stood before the outermost is back once the last release is called. Each release takes its own hold off the stack whatever order the releases come in. `exclusive` takes the rate for the `owner` key the call states: while that hold stands, a hold is admitted only when it states the same key, and every other one is refused with an error naming the key and the rate. That is what lets one caller pin the rate its run is measured at while another agent drives the same engine. double. Finite and `>= 0`. and an exclusive hold states one. A hold that states no key takes the key of the agent the call is attributed to, or a minted `hold#n` when the call carries no agent identity, so every hold answers to a key `engine.releaseTimeScale` accepts and `engine.timeScaleOwner` reports as `id`. `exclusive` takes the rate for the stated key until the hold is released.
| arg | type | description |
|---|---|---|
| scale | number | The rate to run at: 1 is real time, 0.5 half speed, 0 frozen, 2 |
| options | TimeScaleHoldOptions? | `owner` is the key this hold is taken under, a non-empty string, |
examples
local release = engine.holdTimeScale(0.08) ; task.wait(0.12) ; release()
local release = engine.holdTimeScale(1, { exclusive = true, owner = "duel-measurement" })callerLabel(who: any) → string
The name a refusal shows for a caller record (a play-shadow author, the mode's holder, an edit waiter): the name the world's roster holds for it, which tells two agents of one account apart, else its account's username, else its caller key.
| arg | type | description |
|---|---|---|
| who | any |
engineMark(generation: number?) → void
| arg | type | description |
|---|---|---|
| generation | number? |
markBaseline( ) → number
Read this module's own memory — the time-scale holds standing, who wrote the rate last, the rate that stood before any hold, the `onTimeScaleChange` subscribers and the highest watcher id each registry has handed out — and answer with a generation `engine.resetToBaseline` puts exactly that back from. Take it once, before the work whose changes are to be undone.
examples
local mark = engine.markBaseline() -- then run, then engine.resetToBaseline(mark)
resetToBaseline(generation: number?) → number
Put this module's own memory back as `engine.markBaseline` read it: every time-scale hold taken since comes off, every `onTimeScaleChange` subscriber added since is removed, the last writer and the base rate read as they did, the rate in force follows, and the record of who registered each watcher forgets the ids handed out since. The marks taken after `generation` go with the reset.
| arg | type | description |
|---|---|---|
| generation | number? | The mark to restore to; the newest when omitted. |
examples
engine.resetToBaseline(mark)
releaseBaseline(generation: number) → boolean
Drop the mark `generation` names, and every mark taken after it, once the caller that took it is done resetting to it. It touches the marks alone.
| arg | type | description |
|---|---|---|
| generation | number | The mark to drop, as `engine.markBaseline` returned it. |
examples
engine.releaseBaseline(mark) -- the run is over
timeScaleHolds( ) → void
releaseTimeScale(owner: string) → number
| arg | type | description |
|---|---|---|
| owner | string |
offTimeScaleChange(id: number) → boolean
Remove an `engine.onTimeScaleChange` subscriber by its watcher id. Returns true when a live watcher carried that id, false when it named none.
| arg | type | description |
|---|---|---|
| id | number | Watcher id returned by `engine.onTimeScaleChange`. |
examples
local id = engine.onTimeScaleChange(function() end)
engine.offTimeScaleChange(id)
markScriptingBaseline( ) → number
Record the scripting registries — world-event subscriptions, the four lifecycle-watcher lists, and the require cache — as they stand right now, as a mark `engine.resetScriptingState()` restores to. Marks stack: a reset names the generation it restores to, and the marks taken after that one go with it. Returns the new mark's generation, counting from 1. Mark once the engine is serving rather than while it boots: the registries keep growing as the prelude subscribes, the world entrypoint runs and the startup scene loads, so a mark taken partway through sits below the rest of that work and the first reset would remove it.
examples
engine.markScriptingBaseline()
world.on("player_join", function() end)engine.resetScriptingState() -- the subscription above is gone
resetScriptingState(generation: number?) → void
Drop every world-event subscription, lifecycle watcher and cached module registered since the mark `generation` names — the newest `engine.markScriptingBaseline()` when omitted — leaving everything registered before it in place, including the builtin world-entrypoint loader, which subscribes at VM boot and so always sits below any mark. A subscription or watcher that stood at the mark and was removed since goes back in under its own id, with the record of who registered it (`engine.watcherSources`), when its callback is a closure of a module the mark held in the require cache and no component instance's own code removed it. The marks taken after that one go with the reset. A module with a frame on the stack keeps its cache entry and its registrations. Raises when no such mark is in force. Returns per-registry counts of what was removed: `worldEvents`, `modeWatchers`, `worldReadyWatchers`, `worldUnloadingWatchers`, `pauseWatchers`, `deviceRebuiltWatchers`, `memoryPressureWatchers`, `backgroundWatchers`, `modules`, and `total`. returned it; the newest mark when omitted.
| arg | type | description |
|---|---|---|
| generation | number? | The generation to restore to, as `markScriptingBaseline` |
releaseScriptingBaseline(generation: number) → boolean
Drop the scripting mark `generation` names, and every mark taken after it, once the caller that took it is done resetting to it. The registries stay as they stand, and a watcher removed since that only the dropped marks stood to put back is let go. A mark holds the require cache's keys as they stood, so a caller that marks once per run drops each mark when its run is over. returned it.
| arg | type | description |
|---|---|---|
| generation | number | The mark to drop, as `engine.markScriptingBaseline` |
examples
engine.releaseScriptingBaseline(mark) -- the run is over
scriptingRegistryCounts( ) → void
How many subscriptions each scripting registry holds right now, plus the size of the require cache and the generation of the mark in force. Keys: `worldEvents`, `modeWatchers`, `worldReadyWatchers`, `worldUnloadingWatchers`, `pauseWatchers`, `deviceRebuiltWatchers`, `memoryPressureWatchers`, `backgroundWatchers`, `modules`, and `baselineGeneration` (nil when no mark has been taken).
onWorldLoaded(callback: () → void
Register a callback fired (no args) when the world is fully LOADED — its `.world_entrypoint.luau` ran AND its `onWorldLoad` returned (the startup scene loaded, defaults seeded, editor UI mounted). This is strictly AFTER `onWorldReady` (content synced): ready = "bytes are in the VFS"; loaded = "the entrypoint has run". LATCHED — a callback registered after the world is already loaded fires immediately, so a late consumer never misses it and never has to poll. Read the same state synchronously via `engine.worldLoaded`.
| arg | type | description |
|---|---|---|
| callback | ( | Function invoked with no arguments. |
offWorldLoaded(id: number) → boolean
Remove an `onWorldLoaded` subscriber by its watcher id.
| arg | type | description |
|---|---|---|
| id | number |
_fireWorldLoaded(detail: string?) → void
INTERNAL. Mark the world fully loaded and fan out to every `onWorldLoaded` subscriber. Called by the builtin world-entrypoint loader once `onWorldLoad` has returned. Idempotent per load — re-fires on a genuine reload (mirrors a scene's onReady), so the flag is set true and subscribers run on each call. carries as its detail: the loader's account of the frames the load ran across.
| arg | type | description |
|---|---|---|
| detail | string? | Optional JSON text the boot timeline's `world_loaded` mark |
_resetWorldLoaded( ) → void
INTERNAL. Clear the world-loaded latch on unbind/unload so a subsequent bind re-fires onWorldLoaded for the new world.
preview(list: { string }, cap: number) → string
A list as a refusal names it: the first `cap` entries, then how many more.
| arg | type | description |
|---|---|---|
| list | { string } | |
| cap | number |
playStanding( ) → PlayStanding
memberNames(members: { PlayMember }) → string
The callers a list of members names, by roster name where the roster holds one.
| arg | type | description |
|---|---|---|
| members | { PlayMember } |
outsideRefusal(others: { PlayMember }) → string
What a caller outside the play session meets when it writes edit while the session runs for others.
| arg | type | description |
|---|---|---|
| others | { PlayMember } |
tunedFor(standing: PlayStanding) → void
The entities whose tuning an exit from play answers for. A caller leaving a session that runs on answers for the entities it tuned itself. The exit that takes the engine to edit answers for every entity a caller of the session tuned, the leaving caller included, and for tuning no caller was named for; tuning by a caller that never took part was made beside the session and was told so when it was made.
| arg | type | description |
|---|---|---|
| standing | PlayStanding |
takeDiscardArm(standing: PlayStanding, keep: boolean?) → boolean
Spend the deliberate discard the exit `standing` describes takes, and say whether there was one armed in the play session being left. The caller's own arm is spent by every exit it makes. A call that names no caller cannot be told apart from any caller of the session, so the exit that ends the session also takes an arm made for the whole session from the other side of that line: an exit that names no caller takes the arm a named caller made, and a named caller's exit takes the arm a call that named no caller made. One agent whose transport names it on some of its calls and not on others thus arms and leaves as the one caller it is. With `keep`, the answer is the same and every arm stays standing, for the exit that takes it later.
| arg | type | description |
|---|---|---|
| standing | PlayStanding | |
| keep | boolean? |
wholeSession(arm: DiscardArm?) → boolean
| arg | type | description |
|---|---|---|
| arm | DiscardArm? |
leavePlay(standing: PlayStanding, force: boolean) → void
One caller of several leaves play: the session keeps running for the others. The exit answers for this caller's own work alone, the source files it edited in play and the entities it tuned, and the deliberate discard throws away exactly that.
| arg | type | description |
|---|---|---|
| standing | PlayStanding | |
| force | boolean |
unacceptedPlayRefusal(standing: PlayStanding, lead: string, retry: string) → string
What ending the play session `standing` describes would destroy that nobody accepted, as the refusal that names it: the entities the scene does not have, the source files play edited, and the entities tuned in play, each named, with whose work it is and the routes that settle it. `lead` opens the refusal with the call that would end the session, and `retry` closes it with how that call is made again once the work is settled. Nil when ending the session destroys nothing.
| arg | type | description |
|---|---|---|
| standing | PlayStanding | |
| lead | string | |
| retry | string |
guardWorldLeaveFromPlay(opts: { lead: string?, again: string?, keepArm: boolean? }?) → void
A call that leaves the world while the engine is in play: `world.swap`, the branch checkout that swaps, `world.leave`. Leaving the world ends the play session for every caller in it, so the call answers for everything the session holds, the way `engine.setMode("edit", { endSession = true })` does: an agent at the wheel (editor profile, execute() context) meets the same refusal over unaccepted play work, and `engine.discardPlayChanges()` arms the call to proceed without it, spent by the call it allows. `opts.lead` opens the refusal with the call and what it takes down, and `opts.again` closes it with how the call is made again; both name a swap when omitted. `opts.keepArm` answers the same and leaves an armed discard standing, for a call whose own `world.swap` takes it. Raises the refusal; returns when the call may leave the world.
| arg | type | description |
|---|---|---|
| opts | { lead: string?, again: string?, keepArm: boolean? }? |
lspHoldsDirtyFiles( ) → boolean
Whether files the LSP has not yet re-validated stand between a flip into play and the play gate that reads its cache.
waitForLspDrain( ) → void
Waits across frames until the LSP has re-validated every dirty file, on a job off the frame, so the play gate reads a cache that is current. The drain is asked for as awaited, so its slices take their turn with the other work off the frame rather than waiting behind it. Returns at once when the LSP is off, has nothing to drain, or the caller cannot yield: a property write cannot, and its gate checks what is owed in its own frame.
awaitPlayGate( ) → void
Wait, a frame at a time, until the play gate can answer without building in the flip's frame. The gate re-checks the scripts written since the last check in the checker's type environment, and when that environment is not built for the current API surface `preparePlay` builds it off the frame and reads false until it has landed. Called only where the caller can yield.
applyMode(value: string, strict: string?, endSession: boolean?) → void
| arg | type | description |
|---|---|---|
| value | string | |
| strict | string? | |
| endSession | boolean? |
waitForEdit(reason: string?) →
Say that this caller's edit-mode work is waiting on the play session, and get back the call that takes the wait off. One process runs one simulation, so a play session holds the engine in play for every caller outside it, and an agent whose edit-mode work cannot proceed has no way to say so. While this wait stands it rides the run-state block of every response any session gets from this engine, so the callers in the play session learn somebody is waiting for it. Read `engine.playSession` for who they are, and `engine.modeOwner` for who entered play and how long ago. A wait is keyed by the caller the call was attributed to, so a named caller that registers twice moves its own entry forward rather than queueing behind itself: one caller waits once. A call carrying no agent identity is named by nothing to key on, so each such ask stands as its own waiter and the release it handed back takes that one off. Reaching edit mode takes every wait off, so a caller whose release is lost with the task that held it leaves nothing standing.
| arg | type | description |
|---|---|---|
| reason | string? | What this caller is waiting to do, shown beside its name. |
examples
local done = engine.waitForEdit("promote my scene edits")-- ... once the engine reaches edit and the work is taken ...
done()
editWaiters( ) →
Everyone waiting for this engine to leave play so their edit-mode work can run, oldest first. Each entry is `{ key, id, name, reason, heldSeconds }`: `id` is the waiting caller, the same value `vfs.currentAuthor().id` reads, and `heldSeconds` is how long it has been waiting. A session holding play reads this to see whose work it is holding. Empty in edit mode and whenever nobody has said they are waiting.
examples
for _, who in ipairs(engine.editWaiters()) do
log.warn(("%s has waited %.0fs for edit mode"):format(who.name or who.key, who.heldSeconds))end
setMode(mode: string, options: { strict: boolean?, endSession: boolean? }?) →
Change the engine mode with per-call control over the play gate, and read back what the change went past. `engine.mode = value` is the same flip with the defaults. `options.strict = false` lets THIS call enter play while your own content carries error-severity diagnostics. It settles with the call: the world's `lsp.strict_mode` is untouched, so no other session and no later session of the world sees a different gate. The returned `bypassed` array holds the diagnostics the call went past — each `{ path, line, col, code, message, severity }` — and the engine log carries the same list. An error in content another session wrote never gates the flip, so it never appears here; a push still refuses to publish while any of them stands. waives the play gate for this call; `true` or omitted honours the world's `lsp.strict_mode`. `endSession = true` with `"edit"` ends the running play session for every caller in it, whether or not you take part, and answers for everything the session holds (`engine.discardPlayChanges()` arms its discard); without it, an `"edit"` from one of several callers in play takes only that caller out, and one from a caller outside the session is refused. diagnostics this call entered play past (empty when it went past none), and whether an `"edit"` took this caller out of a play session that keeps running for other callers, in which case `mode` still reads `"play"`.
| arg | type | description |
|---|---|---|
| mode | string | `"edit"` or `"play"`. |
| options | { strict: boolean?, endSession: boolean? }? | `{ strict: boolean?, endSession: boolean? }`. `strict = false` |
examples
local report = engine.setMode("play", { strict = false })for _, d in ipairs(report.bypassed) do
print(("entered play past %s:%d — %s"):format(d.path, d.line, d.message))end
__index(_: ?, key: ?) → void
| arg | type | description |
|---|---|---|
| _ | ? | |
| key | ? |
__newindex(_: ?, key: ?, value: ?) → void
| arg | type | description |
|---|---|---|
| _ | ? | |
| key | ? | |
| value | ? |
TimeScaleHoldOptions = { owner: string?, exclusive: boolean? }EditWaiter = {TimeScaleOwner = {Process-level engine state: `engine.profile` (read-only, set once at boot from --profile) and `engine.mode` (read-write, flips edit/play and toggles GameplayPaused as a side effect). Pure-Luau computed properties via metatable __index/__newindex over internal __engineSettings + __mode FFI.Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.