playable
The playable milestone: whether the world is ready to play right now (could someone jump in and play it), what is still missing when it is not, and since when it has been ready. A screen offering Play, a test, a tool or a content run measuring time to first playable reads it, waits on it, or subscribes to it while the world is being built, in edit mode as well as in play. Two things set it. The SCENE sets it when its play entry would spawn a player the person controls: the active scene's player intent is "spawns", a PlayerSpawn names a well-formed PlayerPrototype, the prototype's body carries controls (a component holding an inputMap that activates: every one of the map's .inputBinding controls reads sound, as activation requires) and its camera rig holds the Camera the player sees through, and on a touch device the controls' input map reaches touch. In play it reads the player play spawned: the local player's avatar carrying controls, and a main camera. The AGENT building the world sets it with playable.declare, for a game the scene rule cannot see (a game with no player body, a first version the agent calls ready). source names which of the two set it. The engine judges the scene on every frame it runs, so a change is seen by the next frame, and onChange fires each time the world goes in or out of the playable state. The first time the world became playable since it was opened is kept in first. While a world is being left and the next one opened (a swap, a branch checkout, a reload, a leave) the milestone reads not playable (world.loading). The agent's statement, first and the change count belong to the world they were made in: once the next world is ready they are cleared when it is another world (another guid, or another branch of it) or when either world could not be read, and kept when the same world comes back (a refused move, a reload of the world). A statement made while the move runs is about the world arriving, and stands in it.
require("@builtin::modules.api.engine.playable") -- playable (also available as global 'playable')
The playable namespace: 24 functions.
globals/playable/_carried
playable._carried(report: { client: string, declared: { by: string, note: string?, at: number }? }) -> boolean
Internal: take in the playable statement an agent made in a sub-client
of the user's editor, which the editor hands the user's client so the
person reads the milestone the agent stated. report.client names the
sub-client; report.declared ({ by, note?, at }) is its statement, and
absent it withdraws the statement that sub-client made, leaving one made
anywhere else.
Parameters
report{ client: string, declared: { by: string, note: string?, at: number }? }—{ client, declared? }.
Returns boolean — true when the milestone took the report in.
globals/playable/_judgeCounts
playable._judgeCounts() -> { judged: number, fingerprints: number }
Test-only: how many times the scene has been judged since the engine
started (judged), and how many of those read the scene through its
fingerprint (fingerprints) rather than answering from the counters a
still edit-mode scene's verdict moves with.
Returns { judged: number, fingerprints: number } — { judged, fingerprints }.
globals/playable/_reset
playable._reset()
Test-only: clear the agent's statement, the first moment and the change count, so a suite starts from a freshly opened world.
globals/playable/_worldIdentityDrill
playable._worldIdentityDrill(reader: (() -> string?)?)
Test-only: stand in for reading which world the engine is bound to
(its guid and branch), so a suite drives a move to another world, or a
read that fails, through the engine's own world lifecycle. The reader
returns the identity, or raises to stand for a read that fails. Nil
reads the bound world again; playable._reset does the same.
Parameters
reader(() -> string?)(optional) — The stand-in, or nil.
globals/playable/declare
playable.declare(opts: { by: string?, note: string? }?) -> PlayableState
State that the world is playable, as the agent building it: a first
version ready, or a game the scene rule cannot see. It holds until
playable.withdraw, or until the engine moves to another world (another
guid, or another branch), and readers see source read "agent" (or
"both" while the scene sets it too). While a world is being left and the
next one opened it stands without making the world playable; a statement
made then is about the world arriving, and stands in it. Made in a
sub-client the user's editor runs for an agent, the statement (and its
withdrawal) reaches the user's client too, which reads it in declared
with the sub-client named as client, while it is on the same world and
branch.
Parameters
opts{ by: string?, note: string? }(optional) —{ by?, note? }: who states it (default"agent") and a line saying what is ready.
Returns PlayableState — The state after the statement.
playable.declare({ by = "DotBot", note = "First version: tap the ball to bounce it" })
globals/playable/install
playable.install()
Internal: start the engine's judging loop, which judges the scene on every frame the engine runs so the first playable moment is kept whether or not anything reads it, and follow the world's lifecycle so each world opened starts from its own verdict. Called once by the prelude on the engine thread.
globals/playable/isPlayable
playable.isPlayable() -> boolean
Whether the world is playable right now, set by the scene or by an agent.
Returns boolean — true when playable.
if playable.isPlayable() then showPlayButton() end
globals/playable/offChange
playable.offChange(handle: number) -> boolean
Drop an onChange subscription by its handle.
Parameters
handlenumber— The handleplayable.onChangereturned.
Returns boolean — true when a live subscription carried it.
playable.offChange(h)
globals/playable/onChange
playable.onChange(callback: (PlayableState, PlayableState?) -> ()) -> number
Run a callback each time the world goes in or out of the playable state,
or the source that sets it changes. It fires on the frame the change is
judged, with the new state and the one before it. A callback registered
while the world is playable is not fired for that state; read
playable.state() for it. The subscription ends with the context that
made it as well: a module body's with the module's next run or its leaving
the require cache (the world's content ending as the engine leaves the
world included), a component's with that component instance.
Parameters
callback(PlayableState, PlayableState?) -> ()— Called ascallback(state, previous).
Returns number — The handle playable.offChange takes.
local h = playable.onChange(function(s) playButton.visible = s.playable end)
globals/playable/state
playable.state() -> PlayableState
The milestone as it stands this frame. playable is the verdict;
source names what set it ("scene", "agent" or "both"); scene is the
scene's own verdict and declared the agent's statement; missing lists why
the scene does not set it (each { code, message, entity? }); player names
the spawn, prototype, body, camera and controlling components the verdict
rests on; since is when the current playable stretch began and first the
first time the world reached it since it was opened (each { at, engineTime, frame, source }, at in Unix seconds); changes counts the times the
verdict or its source has changed since then.
Returns PlayableState — The PlayableState.
local s = playable.state()
if not s.playable then print(s.missing[1].message) end
globals/playable/wait
playable.wait(opts: PlayableWaitOpts?) -> (boolean, PlayableState)
Wait until the world is playable, at most timeout seconds of wall
clock (default 60). source = "scene" waits for the scene's own verdict and
source = "agent" for an agent's statement; omitted, either one ends the
wait. Returns at once when it already holds.
Parameters
optsPlayableWaitOpts(optional) —{ timeout?, source? }.
Returns (boolean, PlayableState) — true, state once playable; false, state when the timeout passes first, with state.missing naming what the scene still lacks.
local ok, s = playable.wait({ timeout = 120 })
if not ok then print("not playable yet:", s.missing[1] and s.missing[1].message) end
globals/playable/withdraw
playable.withdraw() -> boolean
Withdraw an agent's statement that the world is playable. The scene's own verdict is unchanged.
Returns boolean — true when a statement stood.
playable.withdraw()
typed/builtin//modules/api/engine/playable/playable/_carried
playable._carried(report: { client: string, declared: { by: string, note: string?, at: number }? }) -> boolean
Internal: take in the playable statement an agent made in a sub-client
of the user's editor, which the editor hands the user's client so the
person reads the milestone the agent stated. report.client names the
sub-client; report.declared ({ by, note?, at }) is its statement, and
absent it withdraws the statement that sub-client made, leaving one made
anywhere else.
Parameters
report{ client: string, declared: { by: string, note: string?, at: number }? }—{ client, declared? }.
Returns boolean — true when the milestone took the report in.
typed/builtin//modules/api/engine/playable/playable/_judgeCounts
playable._judgeCounts() -> { judged: number, fingerprints: number }
Test-only: how many times the scene has been judged since the engine
started (judged), and how many of those read the scene through its
fingerprint (fingerprints) rather than answering from the counters a
still edit-mode scene's verdict moves with.
Returns { judged: number, fingerprints: number } — { judged, fingerprints }.
typed/builtin//modules/api/engine/playable/playable/_reset
playable._reset()
Test-only: clear the agent's statement, the first moment and the change count, so a suite starts from a freshly opened world.
typed/builtin//modules/api/engine/playable/playable/_worldIdentityDrill
playable._worldIdentityDrill(reader: (() -> string?)?)
Test-only: stand in for reading which world the engine is bound to
(its guid and branch), so a suite drives a move to another world, or a
read that fails, through the engine's own world lifecycle. The reader
returns the identity, or raises to stand for a read that fails. Nil
reads the bound world again; playable._reset does the same.
Parameters
reader(() -> string?)(optional) — The stand-in, or nil.
typed/builtin//modules/api/engine/playable/playable/declare
playable.declare(opts: { by: string?, note: string? }?) -> PlayableState
State that the world is playable, as the agent building it: a first
version ready, or a game the scene rule cannot see. It holds until
playable.withdraw, or until the engine moves to another world (another
guid, or another branch), and readers see source read "agent" (or
"both" while the scene sets it too). While a world is being left and the
next one opened it stands without making the world playable; a statement
made then is about the world arriving, and stands in it. Made in a
sub-client the user's editor runs for an agent, the statement (and its
withdrawal) reaches the user's client too, which reads it in declared
with the sub-client named as client, while it is on the same world and
branch.
Parameters
opts{ by: string?, note: string? }(optional) —{ by?, note? }: who states it (default"agent") and a line saying what is ready.
Returns PlayableState — The state after the statement.
playable.declare({ by = "DotBot", note = "First version: tap the ball to bounce it" })
typed/builtin//modules/api/engine/playable/playable/install
playable.install()
Internal: start the engine's judging loop, which judges the scene on every frame the engine runs so the first playable moment is kept whether or not anything reads it, and follow the world's lifecycle so each world opened starts from its own verdict. Called once by the prelude on the engine thread.
typed/builtin//modules/api/engine/playable/playable/isPlayable
playable.isPlayable() -> boolean
Whether the world is playable right now, set by the scene or by an agent.
Returns boolean — true when playable.
if playable.isPlayable() then showPlayButton() end
typed/builtin//modules/api/engine/playable/playable/offChange
playable.offChange(handle: number) -> boolean
Drop an onChange subscription by its handle.
Parameters
handlenumber— The handleplayable.onChangereturned.
Returns boolean — true when a live subscription carried it.
playable.offChange(h)
typed/builtin//modules/api/engine/playable/playable/onChange
playable.onChange(callback: (PlayableState, PlayableState?) -> ()) -> number
Run a callback each time the world goes in or out of the playable state,
or the source that sets it changes. It fires on the frame the change is
judged, with the new state and the one before it. A callback registered
while the world is playable is not fired for that state; read
playable.state() for it. The subscription ends with the context that
made it as well: a module body's with the module's next run or its leaving
the require cache (the world's content ending as the engine leaves the
world included), a component's with that component instance.
Parameters
callback(PlayableState, PlayableState?) -> ()— Called ascallback(state, previous).
Returns number — The handle playable.offChange takes.
local h = playable.onChange(function(s) playButton.visible = s.playable end)
typed/builtin//modules/api/engine/playable/playable/state
playable.state() -> PlayableState
The milestone as it stands this frame. playable is the verdict;
source names what set it ("scene", "agent" or "both"); scene is the
scene's own verdict and declared the agent's statement; missing lists why
the scene does not set it (each { code, message, entity? }); player names
the spawn, prototype, body, camera and controlling components the verdict
rests on; since is when the current playable stretch began and first the
first time the world reached it since it was opened (each { at, engineTime, frame, source }, at in Unix seconds); changes counts the times the
verdict or its source has changed since then.
Returns PlayableState — The PlayableState.
local s = playable.state()
if not s.playable then print(s.missing[1].message) end
typed/builtin//modules/api/engine/playable/playable/wait
playable.wait(opts: PlayableWaitOpts?) -> (boolean, PlayableState)
Wait until the world is playable, at most timeout seconds of wall
clock (default 60). source = "scene" waits for the scene's own verdict and
source = "agent" for an agent's statement; omitted, either one ends the
wait. Returns at once when it already holds.
Parameters
optsPlayableWaitOpts(optional) —{ timeout?, source? }.
Returns (boolean, PlayableState) — true, state once playable; false, state when the timeout passes first, with state.missing naming what the scene still lacks.
local ok, s = playable.wait({ timeout = 120 })
if not ok then print("not playable yet:", s.missing[1] and s.missing[1].message) end
typed/builtin//modules/api/engine/playable/playable/withdraw
playable.withdraw() -> boolean
Withdraw an agent's statement that the world is playable. The scene's own verdict is unchanged.
Returns boolean — true when a statement stood.
playable.withdraw()