Scene states and the FSM
The current state determines which events are handled and which commands run.
SceneFSM holds the current state and the transition rules. FSMConfig contains the initial state, the states map, entry commands, and event handlers under on.
Here is an excerpt from the game configuration. fsm.config.ts
playing: {
on: {
[BlockPuzzleEvents.PlacementRequested]: {
target: 'resolvingPlacement',
actions: ['PlaceBlockCommand'],
},
[BlockPuzzleEvents.RestartRequested]: {
actions: ['RestartBlockPuzzleCommand'],
},
},
},
The FSM ignores events absent from the current state’s on handlers. A rule with actions and no target runs the commands and keeps the current state. RestartRequested works this way.
Transition order
The SDK runs the actions in order. It then switches to the target and runs the new state’s entry commands. So while PlaceBlockCommand runs, the current state is still playing.
Events sent by a command wait in the queue. For example, the FSM handles PlacementCompleted after it changes state.