sml icon indicating copy to clipboard operation
sml copied to clipboard

Clarification on the flow and better use States and Events

Open eraserpencil opened this issue 4 years ago • 1 comments

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

  1. guard of event, followed by action of event
  2. guard of on_exit, followed by action of on_exit,
  3. guard of on_entry followed by corresponding action but rather
  4. guard of an event followed by the guard of the on_exit
  5. action of on_exit followed by action of event
  6. guard on on_entry, followed by action of on_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 States, 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

eraserpencil avatar Nov 19 '20 17:11 eraserpencil

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.

Rijom avatar Dec 06 '20 19:12 Rijom