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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Schema extends ZodMiniType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
authority |
Authority |
handle |
LiveStateHandle<string, Schema> |
state |
ReadonlyLiveState<output<Schema>> |
setLiveStateOptions |
SetLiveStateOptions |
Returns
Section titled “Returns”LiveStateRefusal | null
Example
Section titled “Example”const { state, revision } = readLiveState(world, events);setLiveState(step, events, { ...state, boss: "dragon" }, { expectedRevision: revision });