jonblack/arduino-fsm

When to set m_current_state

nyfelix opened this issue · 0 comments

Hi,
thank you for that wonderful and lean implementation of an FSM.
When test driving it, I came across the following question (probably not an issue):

The m_current_state is set after execution of transition->state_to->on_enter.
This means, you cannot set a trigger in the on_enter function to directly move to the next state.
Is this meant to be like this, or should m_current_state rather be set before execution of transition->state_to->on_enter?

void Fsm::make_transition(Transition* transition)
{
// Execute the handlers in the correct order.
if (transition->state_from->on_exit != NULL)
transition->state_from->on_exit();

if (transition->on_transition != NULL)
transition->on_transition();

if (transition->state_to->on_enter != NULL)
transition->state_to->on_enter();

m_current_state = transition->state_to;