-
Notifications
You must be signed in to change notification settings - Fork 24
Description
If you have to guard against doing illegal transitions, you'll need another finite-state machine implementation (e.g. a switch) to do this. The current FSM implementation creates the very problem FSMs are meant to solve.
Doing the transitions directly is also, let's say, unorthodox.
Usually, you just throw events at the FSM and it transitions in response if it feels like it. E.g. in a platform game, if the player's character is already in the jumping state, pressing the jump button once more won't do anything (unless there is a doubleJumping state the FSM could transition to).
https://en.wikipedia.org/wiki/Finite-state_machine
[An FSM is] an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition. A particular FSM is defined by a list of its states, and the triggering condition for each transition.
Also check what Robert Nystrom (the author of pub and dartfmt) wrote about this topic in his spare time: