sml
sml copied to clipboard
Clarification on the flow and better use States and Events
Hey there! Thanks for the neat library. Unfortunately, the header file is beyond my current level of comprehension and need some clarification on how to better use States and Events.
As I understand thus far, events are triggered with process_event
or dispatch_event
, actions and guards can be used to trigger functions... in a general sense, make things happen. One interesting thing I found out is that the sequence of events is not very intuitive. I have to wrap my ahead around the fact that a transitional event is not really carried as
- guard of
event
, followed by action ofevent
- guard of
on_exit
, followed by action ofon_exit
, - guard of
on_entry
followed by corresponding action but rather - guard of an
event
followed by the guard of theon_exit
- action of
on_exit
followed by action ofevent
- guard on
on_entry
, followed by action ofon_entry
Am I misunderstanding some things here?
In my test, I don't seem to have a use for states and events (actually, I didnt manage to capture logs or prints in them). And in most examples, they are left pretty much vanilla as struct
or class
. With State
s, I understand that they are states, so perhaps it's important to keep some data in them, but I don't know how to make good use of the information inside the states. With Events, it's even more confusing, because the trigger of a transition is with process_event
, where I suppose it's meant to trigger a function with the Event's member variables at best, but I'm not sure if that assumption is in the right direction.
Some examples along with explanation would help if I'm completely wrong in my understanding of States and Events. Thanks
I'm struggling to follow your question. Can you make an example?
It is common for states to be plain structs with no members. There is no need to store anything in them. An event on the other side often has members that allow you to pass information into the state-machine.