Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

setLiveState

setLiveState<Schema>(authority, handle, state, setLiveStateOptions): LiveStateRefusal | null

Writes a live state from a room’s step, against the revision it read: the platform takes it where the state is still at that revision, and every room and page of the game gets it. The room applies the answer on the tick it arrives, and LiveStateSetEvent tells the game the new revision or the refusal, such as stale-revision where another write landed first. A room on an older version keeps the fields a newer one added. Answers a refusal it knows at once, throwing in development, and null where the write went out. A counter every room bumps belongs in a key; live state carries no transaction.

Type Parameter
Schema extends ZodMiniType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameter Type
authority Authority
handle LiveStateHandle<string, Schema>
state ReadonlyLiveState<output<Schema>>
setLiveStateOptions SetLiveStateOptions

LiveStateRefusal | null

const { state, revision } = readLiveState(world, events);
setLiveState(step, events, { ...state, boss: "dragon" }, { expectedRevision: revision });