How to add a state machine to a board
Use a state machine for a door that is locked, unlocked or open, or a quest that is offered, taken or done.
Create the machine
Section titled “Create the machine”-
In the file tree, right-click and choose New state machine. The file is
*.fsm.mmdand holds a mermaidstateDiagram-v2. -
Write the machine in the editor. Every arrow is
From --> To : event, and[*] --> Snames the start:stateDiagram-v2[*] --> LockedLocked --> Unlocked : keyUnlocked --> Open : pushOpen --> Unlocked : pullUnlocked --> Locked : lock -
Fix anything the editor reports against its line. State machine files lists what the editor warns about.
Put it on a board
Section titled “Put it on a board”- Drag the
.fsm.mmdfile from the file tree onto the board. It becomes a State machine node pointing at the file. Alternatively, add a State machine node and pick the machine from the list on its card. - Wire or type the Event the node receives. Leave it blank to read the state without moving the machine. Use
[*]as the event to reset the machine to its start. - If two nodes in the story must drive separate copies of one machine, give each its own Instance name. Give a single quest none: left blank, the instance is the machine’s own name, so every node without one drives the same machine.
Branch on the state
Section titled “Branch on the state”- Add a Switch node and wire the State machine node’s state output into it.
- In the Switch’s rows, type one state name per row. Each row has its own output, taken when the state matches that name.
- Wire the State machine node’s flow out to the rest of the board. It leaves by changed when an arrow fired or the machine was reset, and by unchanged otherwise.
An event the current state has no arrow for is not an error. The machine stays put and the flow takes unchanged, so decide downstream what to do about it.
What is kept
Section titled “What is kept”A machine remembers its state for the whole playthrough, across boards and saves. Starting over resets it.
Related
Section titled “Related”- State machines: why a state machine is a drawing and how it differs from a console variable.
- State machine files: the mermaid syntax the app reads and what it refuses.
- Nodes: the State machine and Switch nodes.
- How to play and test a campaign: check the machine moves as you intend.