state_machine icon indicating copy to clipboard operation
state_machine copied to clipboard

CP-2203 IllegalStateTransitions shouldn't exist

Open mahonnaise opened this issue 10 years ago • 2 comments

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:

http://gameprogrammingpatterns.com/state.html

mahonnaise avatar Aug 31 '15 20:08 mahonnaise

@mahonnaise thanks for the feedback! I read through the post that you linked at it was a good read. I'll admit that I had a bit of tunnel vision when designing this - it fits our use case well, but I agree that it isn't a true FSM. While it won't be right away, I'd definitely like to address this. If you don't mind, could I tag you when there's a PR ready?

evanweible-wf avatar Sep 01 '15 13:09 evanweible-wf

@evanweible-wf @mahonnaise I'm not developing with Dart anymore. Wanna take over this PR?

zeppelin avatar Oct 05 '23 15:10 zeppelin