Closed allistera closed 2 years ago
Hello @allistera,
the current behavior of add_ordered_transitions
will assume the initial state to be the first state in the state sequence. This has been mentioned here:
Conditions will be applied in the states' order BUT start from the initial state (in your case bbb).
The related source code can be found here:
# reorder list so that the initial state is actually the first one
try:
idx = states.index(self._initial)
states = states[idx:] + states[:idx]
first_in_loop = states[0 if loop_includes_initial else 1]
This means that your first transition will be valid with is_grounded
and your second will always fail (has_food
).
Instead of changing the initial state you might want to use i.set_state
instead. This keeps the order of states (and condition checks) as you put them in the states array.
Using set_state
in the initializer works perfectly. Thanks @aleneum
Describe the bug
Conditions within Ordered Transitions do not seem to be taken into account the initial state.
Minimal working example
As you can see in the first example the transition from
hanging out>hungry
is blocked becausehas_food
is True.But in the second example when we set the initial state to
hanging out
the transition to hungry is permitted because it is incorrectly using theis_grounded
function.Expected behavior
When a list is passed to conditions, it takes into account the initial state.