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

Machine

A machine defineMachine made: its trait, and the ways to move and read it.

Type Parameter Default type
Context extends MachineContext MachineContext
Event extends string string
Value StateValue
Tags Record<string, StateTag>
Property Type Description
description? string What it is for, from its config.
is Tags Each state’s tag, which each entity whose record is in the state holds, the world for the world’s machine: world.query(Guard.is.answer), and Guard.is.patrol.watch for a state inside another. They follow the record: a send, a wait and a when move them as they move it, a spawn, the stream and a restore write them with it, and a plain set of state moves them at the start of the next step, before any system reads them.
name string -
reach StreamedReach Which pages a room streams its trait to.
stateNames readonly string[] Every state it has, by the path matches takes: "patrol.watch".
tagNames ReadonlyMap<string, TagTrait> Each tag by the name the dump writes it under: the machine’s name and the state’s path, "guard.patrol.watch".
trait Trait<SchemaFor<MachineRecord<Context, Value>>> Its snapshot: add it to the world for a game’s phases, or spawn it on an entity. Siege.trait({ waves: 3 }) sets its context.

advance(writer): void

Moves on each wait on the writer’s world that its tick has spent, then each machine whose state’s when holds. The writer is a running step or an authority; the tick is the step’s, or the one the world steps next. The engine’s step runs it for every machine, in the order they were declared, on both ends.

Parameter Type
writer Authority | SystemStep

void


read(this, target): MachineRead<Context, Value>

The machine on target as it stands.

Parameter Type
this void
target Entity | World

MachineRead<Context, Value>


send(writer, target, event): boolean

Sends event to the machine on target, the world or an entity. Returns whether a state took it; one no state it is in names leaves it as it was. The writer is as setTrait’s for the machine’s trait: an authority over the entity, or over the world for the world’s machine. Send after a walk over the machine’s trait, or from readEach: updateEach writes its copy of the record back over the send.

Parameter Type
writer EntityAuthority
target Entity
event MachineEvent<Event>

boolean

send(writer, target, event): boolean

Parameter Type
writer Authority
target World
event MachineEvent<Event>

boolean