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

Machine

A machine states 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 -
ownerOnly boolean Whether a room streams its trait to its character’s player alone.
stateNames 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(world, deltaSeconds): void

Counts the waits on world for one step, then moves each machine whose state’s when holds. The engine’s step runs it for every machine, in the order they were declared.

Parameter Type
world World
deltaSeconds number

void


read(target): MachineRead<Context, Value>

The machine on target as it stands.

Parameter Type
target World | Entity

MachineRead<Context, Value>


send(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. 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
target World | Entity
event MachineEvent<Event>

boolean