User Tools

Site Tools


dragengine:modules:dragonscript:behavior_behaviortree

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_behaviortree [2025/03/13 17:31] – [path] dragonlorddragengine:modules:dragonscript:behavior_behaviortree [2026/10/11 15:05] (current) – dragonlord
Line 34: Line 34:
 You can assign actions and conditions without using other behaviors by using one or more factories. The factories are added to the behavior. Upon creating the behavior instances the factories are asked to create and assign BTAction and BTCondition. You can assign actions and conditions without using other behaviors by using one or more factories. The factories are added to the behavior. Upon creating the behavior instances the factories are asked to create and assign BTAction and BTCondition.
 See [[#element_class_example|Element Class Example]] for example code. See [[#element_class_example|Element Class Example]] for example code.
 +
 +See also:
 +  * [[dragengine:modules:dragonscript:behaviortrees|Behavior Trees]]
  
 ====== Instance Counts ====== ====== Instance Counts ======
Line 46: Line 49:
   * Type: string   * Type: string
   * Default Value: empty string   * Default Value: empty string
-  * Expected File Type: ''*.debtree'' +  * Expected File Type: ''*.debt'' 
-  * Example (*.deeclass) <code xml><string name='behaviorTree.path'>actor.debtree</string></code>+  * Example (*.deeclass) <code xml><string name='behaviorTree.path'>actor.debt</string></code>
  
 ===== run ===== ===== run =====
Line 68: Line 71:
 ===== behaviorTreeRestarted ===== ===== behaviorTreeRestarted =====
 Behavior tree has been restarted. Behavior tree has been restarted.
 +
 +
 +====== Behavior Tree Actions ======
 +
 +This behavior adds these behavior tree actions.
 +
 +===== element.set =====
 +
 +Set owner element parameters.
 +
 +^Parameter^Value^Description^
 +|visible|true,false|Set if element is visible.|
 +|touchable|true,false|Set if element is touchable.|
 +
 +This is an example of using this action to fully hide the owner element:
 +<code xml>
 +<action name='element.set'>
 +  <parameter name='visible'>false</parameter>
 +  <parameter name='touchable'>false</parameter>
 +</action>
 +</code>
 +
 +
 +===== element.update =====
 +
 +Update owner element.
 +
 +^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.|
 +|log|string|Print a log message using Element.log() function.|
 +
 +This is an example of using this action to dispose element:
 +<code xml>
 +<action name='element.set'>
 +  <parameter name='dispose'/>
 +</action>
 +</code>
 +
 +===== gameWorld =====
 +
 +Runs action from game world behavior [[gwbehavior_btsm|GWBehaviorBTSM]]. Game world behaviors can add behavior tree actions to GWBehaviorBTSM similar to how element class behaviors can add behavior tree actions to this behavior. This allows behavior trees to access actions specific to a game world. The action is run as if it has been added to this behavior. All parameters defined in the action are passed to the game world actionndition with the addition of the parameter ''element'' set to the behavior element owning the state machine. If the element owning this behavior is not in a game world or the action can not be found, nothing is done.
 +
 +^Parameter^Value^Description^
 +|action|string|Name of action to run.|
 +
 +This is an example of using this action to spawn a new element:
 +<code xml>
 +<action name='gameWorld'>
 +  <parameter name='action'>spawn</parameter>
 +  <parameter name='class'>MyGameObjectClass</parameter>
 +  <parameter name='properties'>propertyName1:propertyValue1 propertyName2:propertyValue2</parameter>
 +  <parameter name='spawnPoint'>spawn point name</parameter>
 +</action>
 +</code>
 +
 +====== Behavior Tree Conditions ======
 +
 +This behavior adds these behavior tree conditions.
 +
 +===== element.check =====
 +
 +Evaluate owner element parameters.
 +
 +^Parameter^Value^Description^
 +|element.visible|true,false|Element is visible or not.|
 +|element.touchable|true,false|Element is touchable 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.|
 +
 +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:
 +<code xml>
 +<action name='myAction' id='doing something'>
 +  <condition>element.check</condition>
 +  <parameter name='element.visible'>true</parameter>
 +  <parameter name='element.touchable'>true</parameter>
 +  <parameter name='element.inGameWorld'>true</parameter>
 +  <parameter name='element.hasParent'>false</parameter>
 +</action>
 +</code>
 +
 +===== gameWorld =====
 +
 +Evaluate condition from game world behavior [[gwbehavior_btsm|GWBehaviorBTSM]]. Game world behaviors can add behavior tree conditions to GWBehaviorBTSM similar to how element class behaviors can add behavior tree conditions to this behavior. This allows behavior trees to access conditions specific to a game world. The condition is evaluated as if it has been added to this behavior. All parameters defined in the condition are passed to the game world condition with the addition of the parameter ''element'' set to the behavior element owning the state machine. If the element owning this behavior is not in a game world or the condition can not be found, false is returned.
 +
 +^Parameter^Value^Description^
 +|gameWorld.condition|string|Name of condition to evaluate.|
 +
 +This is an example of using this condition to evaluate a game state:
 +<code xml>
 +<action name='myAction' id='doing something'>
 +  <condition>gameWorld</condition>
 +  <parameter name='gameWorld.condition'>winningCondition.check</parameter>
 +  <parameter name='gameWorld.condition.foundCounts'>10</parameter>
 +</action>
 +</code>
  
 ====== Required Behaviors ====== ====== Required Behaviors ======
Line 101: Line 199:
   func new()   func new()
     var ECBehaviorBehaviorTree btbehavior = ECBehaviorBehaviorTree.new(this)     var ECBehaviorBehaviorTree btbehavior = ECBehaviorBehaviorTree.new(this)
-    btbehavior.getPath().setValue("/content/myBehavior.debtree")+    btbehavior.getPath().setValue("/content/myBehavior.debt")
     btbehavior.getRun().setValue(true)     btbehavior.getRun().setValue(true)
          
Line 119: Line 217:
   func new()   func new()
     var ECBehaviorBehaviorTree btSpecific = ECBehaviorBehaviorTree.new(this, "specific")     var ECBehaviorBehaviorTree btSpecific = ECBehaviorBehaviorTree.new(this, "specific")
-    btSpecific.getPath().setValue("/content/mySpecificBehavior.debtree")+    btSpecific.getPath().setValue("/content/mySpecificBehavior.debt")
     btSpecific.getRun().setValue(true)     btSpecific.getRun().setValue(true)
          
     var ECBehaviorBehaviorTree btIdle = ECBehaviorBehaviorTree.new(this, "idle")     var ECBehaviorBehaviorTree btIdle = ECBehaviorBehaviorTree.new(this, "idle")
-    btIdle.getPath().setValue("/content/myIdleBehavior.debtree")+    btIdle.getPath().setValue("/content/myIdleBehavior.debt")
     btIdle.getRun().setValue(true)     btIdle.getRun().setValue(true)
          
Line 139: Line 237:
   func new()   func new()
     var ECBehaviorBehaviorTree btree = ECBehaviorBehaviorTree.new(this)     var ECBehaviorBehaviorTree btree = ECBehaviorBehaviorTree.new(this)
-    btSpecific.getPath().setValue("/content/basic.debtree")+    btSpecific.getPath().setValue("/content/basic.debt")
     //btSpecific.getRun().setValue(false) // the default is false     //btSpecific.getRun().setValue(false) // the default is false
          
Line 151: Line 249:
   func new()   func new()
     // load behavior tree to use. this is not required but allows to use different     // load behavior tree to use. this is not required but allows to use different
-    // behavior trees for different AI routines. if not used the "/content/basic.debtree"+    // behavior trees for different AI routines. if not used the "/content/basic.debt"
     // would be used as defined in MyElementClass.     // would be used as defined in MyElementClass.
     var BehaviorTree btree = BaseGameApp.getApp().getLoaders() \     var BehaviorTree btree = BaseGameApp.getApp().getLoaders() \
-      .getBehaviorTree().loadFromFile("/content/aiRoutine1.debtree")+      .getBehaviorTree().loadFromFile("/content/aiRoutine1.debt")
          
     // create context. BAAIBehaviorTree requires a BTContextAI subclass hence we can     // create context. BAAIBehaviorTree requires a BTContextAI subclass hence we can
Line 203: Line 301:
   <behavior type='ECBehaviorBehaviorTree'>   <behavior type='ECBehaviorBehaviorTree'>
     <!-- set element properties. omit property prefix if used inside behavior tag -->     <!-- set element properties. omit property prefix if used inside behavior tag -->
-    <string name='.path'>actor.debtree</string>+    <string name='.path'>actor.debt</string>
   </behavior>   </behavior>
      
dragengine/modules/dragonscript/behavior_behaviortree.1741887093.txt.gz · Last modified: by dragonlord