Skip to content

Commit e0631bd

Browse files
amorygaliliauscompgeek
authored andcommitted
Fix timed states expiring immediately when run twice (#89)
Fixes: #88
1 parent 94fbc9d commit e0631bd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

magicbot/state_machine.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,19 @@ def execute(self):
516516
# determine if the time has passed to execute the next state
517517
# -> intentionally comes first,
518518
if state is not None and state.expires < tm:
519+
520+
previous_state = state
521+
519522
if state.next_state is None:
520523
state = None
521524
else:
522525
self.next_state(state.next_state)
523526
new_state_start = state.expires
524527
state = self.__state
528+
529+
# Reset the expired time to prevent the state from expiring
530+
# immediately if it's ran a second time
531+
previous_state.expires = 0xffffffff
525532

526533
# deactivate the current state unless engage was called or
527534
# must_finish was set

0 commit comments

Comments
 (0)