3 ms·
I really have no idea what you're trying to say here. If a system responds to events it's in a state? Is anything not a state machine by this definition? Any
by jayd16 4y ago
I really have no idea what you're trying to say here. If a system responds to events it's in a state? Is anything not a state machine by this definition?
Anyway, my point was that these are all just conceptual models and another conceptual model that's useful is one with non-atomic transitions.
- layer8 4y agoA state is a (mathematical) function from events to the next state. There is a set of events that can potentially occur, and the function tells you what the next state will be given that event. That’s the mathematical definition of a state machine. You can reverse-engineer what states a system can be in by considering what those possible functions are. For example, consider a state A of some object in your game. For event E (say, the player presses some specific button), the object may transition to state B. For a different event F (say, the object collides with a particular type of other object), it may transition to state C. For yet another event G, the object may remain in state A. Thus the function corresponding to A is { E -> B, F -> C, G -> A } (assuming that E, F, G are the only possible events). Now, you’re saying that the object can be within the transition from (say) A to B. The question is, if one of the possible events occurs during that transition, what does the corresponding function look like? For example, if event F occurs, does the object still continue to go to B, or does it maybe now go to C, or to yet another state? You can write down the corresponding function. If that function is the same as the A function, then that means that the object is actually still in state A. If the function is the B function, then it means the object is actually already in state B. If the function is different from both the A and the B function, then it means the object is actually in a third separate state. Note that an event can also be “the transition animation has finished playing”. The point is, using that functional definition of states (which is the usual definition of state machines or FSAs), for any system with non-atomic transitions there is an equivalent state machine with atomic transitions, and that latter one is what is normally understood to constitute a proper state machine.
- layer8 4y agoOne thing to add: A major benefit of state machines is that you can clearly reason about its behavior. If, however, you have non-atomic state transitions, the behavior during a transition, i.e. how it reacts to events occurring during a transition, is unclear. The reason why state transitions are normally considered to be atomic is so that the system is in a well-defined state at every point in time, so that in turn the behavior of the system is well-defined at every point in time.