User Tools

Site Tools


dragengine:modules:dragonscript:statemachines

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
dragengine:modules:dragonscript:statemachines [2026/10/09 20:02] – [State Machines] dragonlorddragengine:modules:dragonscript:statemachines [2026/10/13 16:25] (current) – dragonlord
Line 16: Line 16:
 States can have __enter actions__ and __exit actions__. __Enter actions__ run after activating the state. Exit actions run before switching to another state. Enter and exit actions both can have conditions which determine if the action is run or not. Enter actions can have a __state change__ assigned. If an enter action with a state change is run the state changes immediately to the specified state and all enter actions afterwards are ignored. This can be used to automatically transition into another state for example if a pre-condition is not fulfilled or an earlier action failed to run properly. In particular no action can be assigned in which case the enter action only serves the purpose to transition into another state if its conditions fail. In addition states can be assigned an __auto-transition state__. If all enter actions are processed and the state has an auto-transition state assigned the auto-transition state is immediately activated. This allows to create pass-through states which only run a couple of enter actions then transition into the final state. States can have __enter actions__ and __exit actions__. __Enter actions__ run after activating the state. Exit actions run before switching to another state. Enter and exit actions both can have conditions which determine if the action is run or not. Enter actions can have a __state change__ assigned. If an enter action with a state change is run the state changes immediately to the specified state and all enter actions afterwards are ignored. This can be used to automatically transition into another state for example if a pre-condition is not fulfilled or an earlier action failed to run properly. In particular no action can be assigned in which case the enter action only serves the purpose to transition into another state if its conditions fail. In addition states can be assigned an __auto-transition state__. If all enter actions are processed and the state has an auto-transition state assigned the auto-transition state is immediately activated. This allows to create pass-through states which only run a couple of enter actions then transition into the final state.
  
-Upon receiving an __event__ the state machine checks transitions defined in the current state from the first defined to the last defined. The first transition matching the event with all of its conditions evaluating to true is used. All matching transitions afterwards are ignored.If no transition matches the event is discarded. It is thus fully legit to send an event to a state machine for states not supporting this particular event. Transitions can have __actions__ assigned. They behave similar to enter actions of states. In particular they can also contain a state change which is useful for situations where actions are unable to properly to transition into an error type state. Transitions typically have a __next state__ assigned but this is optional. If no next state is set the transition only runs actions and stays in the current state. If all actions finished running and a next state is set then the state changes to the next state. If a next state is set the transition first switches the state machine to the null state to run exit actions. Then the transition actions are run. Afterward the state is changed.+Upon receiving an __event__ the state machine checks transitions defined in the current state from the first defined to the last defined. If no transition is found the global transitions in the state machine itself are check. The first transition matching the event with all of its conditions evaluating to true is used. All matching transitions afterwards are ignored.If no transition matches the event is discarded. It is thus fully legit to send an event to a state machine for states not supporting this particular event. Transitions can have __actions__ assigned. They behave similar to enter actions of states. In particular they can also contain a state change which is useful for situations where actions are unable to properly to transition into an error type state. Transitions typically have a __next state__ assigned but this is optional. If no next state is set the transition only runs actions and stays in the current state. If all actions finished running and a next state is set then the state changes to the next state. If a next state is set the transition first switches the state machine to the null state to run exit actions. Then the transition actions are run. Afterward the state is changed.
  
 Transitions can also define a __delegate event__ instead of a next state. If delegate event is set the transition runs all actions then runs the delegate event on the state machine. This does not count as transition in transition situation since the delegate event replaces the current event. Delegate events are useful to run shared transition logic without importing the logic into each transition. Instead a unique event is used which can be easily reused and overwritten to make state machines cleaner and more stable. Transitions can also define a __delegate event__ instead of a next state. If delegate event is set the transition runs all actions then runs the delegate event on the state machine. This does not count as transition in transition situation since the delegate event replaces the current event. Delegate events are useful to run shared transition logic without importing the logic into each transition. Instead a unique event is used which can be easily reused and overwritten to make state machines cleaner and more stable.
Line 64: Line 64:
 } }
 state --> transition state --> transition
 +stateMachine --> transition
 transition --> action transition --> action
  
dragengine/modules/dragonscript/statemachines.1791576177.txt.gz · Last modified: by dragonlord