User Tools

Site Tools


dragengine:modules:dragonscript:behavior_statemachine

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dragengine:modules:dragonscript:behavior_statemachine [2026/10/12 12:00] – dragonlorddragengine:modules:dragonscript:behavior_statemachine [2026/11/18 16:37] (current) – dragonlord
Line 68: Line 68:
  
 This behavior adds these state machine actions. This behavior adds these state machine actions.
 +
 +===== self =====
 +
 +Set state machine parameters.
 +
 +^Parameter^Value^Description^
 +|debug.name|string|Set logging name. This name is prepended to logs if enabled.|
 +|debug.targets|list|List of whitespace separated targets to log. Valid targets: ''actions'', ''transitions'', ''stateChanges''. Empty list disables logging.|
 +
 +This is an example of using this action to fully hide the owner element:
 +<code xml>
 +<action name='self'>
 +  <parameter name='debug.name'>SM-Debug</parameter>
 +  <parameter name='debug.targets'>actions transitions stateChanges</parameter>
 +</action>
 +</code>
  
 ===== element.set ===== ===== element.set =====
Line 74: Line 90:
  
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
-|visible|true,false|Set if element is visible.| +|visible|''true'', ''false''|Set if element is visible.| 
-|touchable|true,false|Set if element is touchable.|+|touchable|''true'', ''false''|Set if element is touchable.|
  
 This is an example of using this action to fully hide the owner element: This is an example of using this action to fully hide the owner element:
Line 84: Line 100:
 </action> </action>
 </code> </code>
- 
  
 ===== element.update ===== ===== element.update =====
Line 92: Line 107:
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
 |dispose| |Dispose of owner element. Make sure this is the last action run in a transition or state. Running actions afterwards can lead to problems.| |dispose| |Dispose of owner element. Make sure this is the last action run in a transition or state. Running actions afterwards can lead to problems.|
 +|teleport|''spawn'', ''coordsys''|<WRAP>Teleport owner element to target location. Supports these target types:
 +  * ''spawn'': SpawnPoint instance.
 +  * ''coordsys'': Conversation coordinate system managed by an [[behavior_convocoordsystem|ECBehaviorConvoCoordSystem]] instance.
 +If element is [[behavior_attachable|attachable]], detaches first if attached.</WRAP>|
 +|teleport.target|string|Identifier of target|
 |log|string|Print a log message using Element.log() function.| |log|string|Print a log message using Element.log() function.|
  
Line 98: Line 118:
 <action name='element.set'> <action name='element.set'>
   <parameter name='dispose'/>   <parameter name='dispose'/>
 +</action>
 +</code>
 +
 +This is an example of using this action to teleport the element to a spawn point:
 +<code xml>
 +<action name='element.set'>
 +  <parameter name='teleport'>spawn</parameter>
 +  <parameter name='teleport.target'>portal1.exit</parameter>
 </action> </action>
 </code> </code>
Line 108: Line 136:
  
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
 +|interactElement.assign|string|Assign event element to [[behavior_interactelement|ECBehaviorInteractElement]] with identifier matching value string.|
 +|interact|string|Run interaction with name value on event element.|
 +|interact.parameters|string|Optional parameters to use with ''interaction''.|
 |runEvent|string|Run named event on all ECBehaviorStateMachine instance of event element with the state machine element as event parameter.| |runEvent|string|Run named event on all ECBehaviorStateMachine instance of event element with the state machine element as event parameter.|
  
Line 123: Line 154:
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
 |action|string|Name of action to run.| |action|string|Name of action to run.|
-|receiveEvents|true,false|Enable receiving game world events|+|receiveEvents|''true'', ''false''|Enable receiving game world events| 
 +|runEvent|string|Run event on all state machines of element set to receive game world events. The state machine owner is set as event parameter.|
  
 This is an example of using this action to spawn a new element: This is an example of using this action to spawn a new element:
Line 132: Line 164:
   <parameter name='properties'>propertyName1:propertyValue1 propertyName2:propertyValue2</parameter>   <parameter name='properties'>propertyName1:propertyValue1 propertyName2:propertyValue2</parameter>
   <parameter name='spawnPoint'>spawn point name</parameter>   <parameter name='spawnPoint'>spawn point name</parameter>
 +</action>
 +</code>
 +
 +This is an example of using this action to run event on [[appbehavior_behaviorstatemachine|application state machines]]:
 +<code xml>
 +<action name='gameWorld'>
 +  <parameter name='action'>app.btsm.runEvent</parameter>
 +  <parameter name='event'>fade over black</parameter>
 </action> </action>
 </code> </code>
Line 144: Line 184:
  
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
-|element.visible|true,false|Element is visible or not.| +|element.visible|''true'', ''false''|Element is visible or not.| 
-|element.touchable|true,false|Element is touchable or not.| +|element.touchable|''true'', ''false''|Element is touchable or not.| 
-|element.inGameWorld|true,false|Element is located in game world or not.| +|element.inGameWorld|''true'', ''false''|Element is located in game world or not.| 
-|element.hasParent|true,false|Element is parented to another element or not.|+|element.hasParent|''true'', ''false''|Element is parented to another element or not.|
  
 This is an example of using this condition to check if the element is visible, touchable, in a game world and not parented to another element: This is an example of using this condition to check if the element is visible, touchable, in a game world and not parented to another element:
Line 169: Line 209:
 |eventElement.flags.set|string|Event element has [[behavior_flags|ECBehaviorFlags]] with named flag set.| |eventElement.flags.set|string|Event element has [[behavior_flags|ECBehaviorFlags]] with named flag set.|
 |eventElement.flags.clear|string|Event element has [[behavior_flags|ECBehaviorFlags]] with named flag cleared.| |eventElement.flags.clear|string|Event element has [[behavior_flags|ECBehaviorFlags]] with named flag cleared.|
 +|eventElement.interactElement.assigned|string|Event element is assigned to [[behavior_interactelement|ECBehaviorInteractElement]] with identifier matching value string.|
 +|eventElement.interactElement.assigned.not|string|Event element is not assigned to [[behavior_interactelement|ECBehaviorInteractElement]] with identifier matching value string.|
  
 This is an example of using this action: This is an example of using this action:
Line 264: Line 306:
 ====== Behavior Tree Actions ====== ====== Behavior Tree Actions ======
  
-This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''attachSlot'' with ''attachSlot(id)''.+This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''stateMachine'' with ''stateMachine(id)''.
  
-===== attachSlot.update =====+===== stateMachine.set =====
  
-Update attach slot.+Set state machine parameters.
  
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
-|detach|empty string, ''dispose''|Detach attachable if one is present. If value is ''dispose'' dispose of attachable after detaching it| +|reset| |Reset state machine to initial state.| 
-|interactElement.assign|string|Assign attached element to [[behavior_interactelement|ECBehaviorInteractElement]] with identifier matching value string. Action fails if no element is attached or interact element behavior is absent| +|state|string|Set state machine to named state.|
-|interact|string|Interact with attachable. If element is absent action fails. Runs interaction with name value. If interaction with name value is absent fails action. If interaction returns false fails action. Otherwise action succeeds.| +
-|interact.parameters|string|Optional parameters to use with ''interaction''.|+
  
-This is an example of using this action:+This is an example of using this action to switch state machine to state ''jump to state'':
 <code xml> <code xml>
-<action name='attachSlot.set'> +<action name='stateMachine.set'> 
-  <parameter name='detach'>dispose</parameter>+  <parameter name='state'>jump to state</parameter>
 </action> </action>
 </code> </code>
  
-===== attachSlot.check =====+===== stateMachine.event =====
  
-Check one or more attach slot parameters. Action succeeds if all parameter value matches their respective attach slot parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a attach slot parameter matches (or not).+Run event on state machine.
  
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
-|empty|''true'', ''false''|Attach slot is empty or not| +|id|string|Identifier of event to run.| 
-|interact.name|string|Name of interaction| + 
-|interact.has|''true'', ''false''|Has attachable and interaction with name ''interaction.name'' is present| +This is an example of using this action to run event ''do something'' on the current state machine state: 
-|interact.query|''true'', ''false''|Interact with attachable and test result. Condition is true if attachable is present, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).| +<code xml> 
-|interact.parameters|string|Optional parameters to use with ''interaction.query''.|+<action name='stateMachine.event'> 
 +  <parameter name='id'>do something</parameter> 
 +</action> 
 +</code> 
 + 
 +===== stateMachine.check ===== 
 + 
 +Check one or more state machine parameters. Action succeeds if all parameter value matches their respective state machine parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a state machine parameter matches (or not). 
 + 
 +^Parameter^Value^Description^ 
 +|state|string|Current state machine state identifier matches value.| 
 +|state.not|string|Current state machine state identifier does not match value.| 
 +|state.starts|string|Current state machine state identifier begins with value.| 
 +|state.starts.not|string|Current state machine state identifier does not begin with value.| 
 +|state.ends|string|Current state machine state identifier ends with value.| 
 +|state.ends.not|string|Current state machine state identifier does not end with value.| 
 +|state.contains|string|Current state machine state identifier contains value.| 
 +|state.contains.not|string|Current state machine state identifier does not contain value.|
 |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled| |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled|
  
-This is an example of using this action:+This is an example of using this action to run a sequence only if state is ''ready state'':
 <code xml> <code xml>
 <sequence> <sequence>
-  <action name='attachSlot.check'> +  <action name='stateMachine.check'> 
-    <parameter name='empty'>false</parameter>+    <parameter name='state'>ready state</parameter>
   </action>   </action>
-  <!-- actions here run only if attach slot is not empty, hence an attachable is present -->+  <!-- actions here run only if state machine is in the expected state. -->
 </sequence> </sequence>
 </code> </code>
Line 307: Line 364:
 ====== Behavior Tree Conditions ====== ====== Behavior Tree Conditions ======
  
-This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''attachSlot'' with ''attachSlot(id)''.+This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''stateMachine'' with ''stateMachine(id)''.
  
-===== attachSlot.check =====+===== stateMachine.check =====
  
-Check one or more attach slot parameters. Conditions returns true if all parameter value match their respective attach slot parameter. This condition is typically used to run an action or sequence of actions as long as attach slot conditions are true.+Check one or more state machine parameters. Conditions returns true if all parameter value match their respective state machine parameter. This condition is typically used to run an action or sequence of actions as long as state machine conditions are true.
  
 ^Parameter^Value^Description^ ^Parameter^Value^Description^
-|attachSlot.empty|''true'', ''false''|Attach slot is empty or not| +|stateMachine.state|string|Current state machine state identifier matches value.| 
-|attachSlot.interact.name|string|Name of interaction| +|stateMachine.state.not|string|Current state machine state identifier does not match value.| 
-|attachSlot.interact.has|''true'', ''false''|Has attachable and interaction with name ''interaction.name'' is present| +|stateMachine.state.starts|string|Current state machine state identifier begins with value.| 
-|attachSlot.interact.query|''true'', ''false''|Interact with attachable and test result. Condition is true if attachable is present, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).| +|stateMachine.state.starts.not|string|Current state machine state identifier does not begin with value.| 
-|attachSlot.interact.parameters|string|Optional parameters to use with ''interaction.query''.|+|stateMachine.state.ends|string|Current state machine state identifier ends with value.| 
 +|stateMachine.state.ends.not|string|Current state machine state identifier does not end with value.| 
 +|stateMachine.state.contains|string|Current state machine state identifier contains value.| 
 +|stateMachine.state.contains.not|string|Current state machine state identifier does not contain value.|
  
-This is an example of using this condition:+This is an example of using this condition to run an action only if state is ''ready state'':
 <code xml> <code xml>
 <action name='myAction' id='doing something'> <action name='myAction' id='doing something'>
-  <parameter name='attachSlot.empty'>false</parameter> +  <condition>stateMachine.check</condition> 
-  <condition>attachSlot.check</condition>+  <parameter name='stateMachine.state'>ready state</parameter>
 </action> </action>
 </code> </code>
dragengine/modules/dragonscript/behavior_statemachine.1791806412.txt.gz · Last modified: by dragonlord