Setting values in a subsequent State from an Action is very useful for configuring subsequent behavior, e.g. from data in an Event. I find this works successfully only when the subsequent State is simple, i.e., is not a submachine.
The attached code implements a programmable counter in two ways:
- A regular struct State stores the current count and the amount to increment. The increment amount is taken from the event that begins the counting. Subsequent INCREMENT events cause the count to be increased by the stored increment amount.
- Incrementing is performed by a sub state machine. The total and the amount to increment are maintained as data members as before.
In the second case, the amount to increment remains at zero, and the count does not change.
bug.cpp