Skip to content

tickFsm

tickFsm<TCtx, TKey>(fsm, states, ctx, dtMs): void

Defined in: src/modules/fsm/fsm.ts:48

Advance a machine by one tick: accumulate time-in-state, run the current state’s update, and on a returned key transition — run the old state’s onExit, switch, reset elapsedMs, run the new state’s onEnter. Returning the same key (or null) stays without re-entering.

Single-machine: to drive many entities, loop them and call tickFsm per entity, supplying whatever per-entity context the handlers need (e.g. set ctx.currentEntity before each call).

Contract: update must return null or a key present in states (returning an unmapped key throws on the follow-up onEnter), and a handler must not call tickFsm on the same machine (no re-entrancy).

TCtx

TKey extends string

Fsm<TKey>

FsmStates<TCtx, TKey>

TCtx

number

void