3

I am defining a state machine and would like to have the machine to "run" when the object is created. With that in mind I left out the triggers on all the transitions (and only defined guards). It seems though that a created object stays in the first state if not triggered further? How can I avoid having to call the trigger explicitly? If I do execute a trigger, all subsequent states are passed by that (one) trigger call? Is there something "special" with the first state?

1 Answers1

3

The first state is special in not needing a trigger. The transition from start-state is executed on object creation.

To mimic the behavior you are looking for you can use the same trigger method on all other transitions. These transitions are guarded so that only 1 transition is valid at a time. But you will need to actually execute this single trigger to make anything happen.

enter image description here

You can now check if triggering is possible and if so trigger by this pseudo code: if self.trigger? then self.trigger

Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15