Appearance
twine / StateMachine
Class: StateMachine โ
Defined in: twine/src/state-machine.ts:34
A scoreboard state machine for quests, dialogue, puzzles and story flow.
The dispatch is one if/elif chain, so a transition doesn't also run the new state in the same tick. Call the returned dispatch from a module's onTick.
Constructors โ
Constructor โ
new StateMachine(
dp,name,instance?):StateMachine
Defined in: twine/src/state-machine.ts:43
Parameters โ
dp โ
Datapack
name โ
string
instance? โ
string = ...
Returns โ
StateMachine
Properties โ
name โ
readonlyname:string
Defined in: twine/src/state-machine.ts:45
Methods โ
build() โ
build():
FunctionRef
Defined in: twine/src/state-machine.ts:111
Emits the machine's load setup and tick dispatch, and returns the dispatch to call from onTick.
Returns โ
FunctionRef
go() โ
go(
ctx,label):void
Defined in: twine/src/state-machine.ts:99
Jumps to label now: runs the current onExit, sets the state, runs label's onEnter. For event-driven jumps outside the dispatch.
Parameters โ
ctx โ
FunctionContext
label โ
string
Returns โ
void
initial() โ
initial(
label):this
Defined in: twine/src/state-machine.ts:66
Set the state the machine starts in (seeded in load).
Parameters โ
label โ
string
Returns โ
this
is() โ
is(
label):ExpressionNode
Defined in: twine/src/state-machine.ts:85
A condition that holds while the machine is in label - for external gating.
Parameters โ
label โ
string
Returns โ
ExpressionNode
state() โ
state(
label,config?):this
Defined in: twine/src/state-machine.ts:58
Declare a state and its lifecycle bodies.
Parameters โ
label โ
string
config? โ
StateConfig = {}
Returns โ
this
transition() โ
transition(
from,to,when):this
Defined in: twine/src/state-machine.ts:72
A guarded transition: while in from, switch to to once when holds.
Parameters โ
from โ
string
to โ
string
when โ
ExpressionNode
Returns โ
this