-
Hello, Can I create a global event that would not be bound to one state? class TrafficLightMachine(StateMachine):
"A traffic light machine"
green = State("Green", initial=True)
yellow = State("Yellow")
red = State("Red")
honk = ?
def on_honk(self):
print("honk) How should I define honk so it can be triggered in any state? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
fgmacedo
Feb 16, 2023
Replies: 1 comment 5 replies
-
Hi @yoavweber , One example of solution is to create class TrafficLightMachine(StateMachine):
"A traffic light machine"
green = State("Green", initial=True)
yellow = State("Yellow")
red = State("Red")
honk = green.to.itself(internal=True) | yellow.to.itself(internal=True) | red.to.itself(internal=True)
def on_honk(self):
print("honk")
If this not helps, can you elaborate more your expected behaviour?
Please refer to these docs, they can help clarify the current behaviour:
Best regards! |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
fgmacedo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @yoavweber ,
One example of solution is to create
internal
transitions on each state:on_enter*
oron_exit*
hooks will NOT be called.on_hook
will be called.If this not helps, can you elaborate more your expected behaviour?