User Tools

Site Tools


dragengine:modules:dragonscript:behavior_behaviortreeflags

ECBehaviorBehaviorTreeFlags

Behavior element behavior adding flags support to behavior tree support.

Behavior adds behavior tree actions and conditions to an ECBehaviorBehaviorTree allowing scripts and behavior trees to set, clear and check flags.

Instance Counts

This behavior can be added multiple times to an element for each ECBehaviorBehaviorTree. Each instance creates an own set of behavior tree actions, conditions and flags.

Element Class Properties

Element class properties have the prefix behaviorTreeFlags. or behaviorTreeFlags({id}). if id is not empty.

Events

This behavior has no events.

Behavior Tree Actions

This behavior adds these behavior tree actions.

flags.set

Set a flag. As parameter use flag to select the flag to set. Use optional parameter clear to clear flag. This action immediately returns and does not require a rule identifier.

This is an example of using this action:

<action name='flags.set'>
  <parameter name='flag'>arrived at target</parameter>
</action>
 
This is an example of using this action to clear flag:
<code xml>
<action name='flags.set'>
  <parameter name='flag'>arrived at target</parameter>
  <parameter name='clear'/>
</action>

flags.check

Checks if flag is set. Use as parameter flag to select the flag to check. Use as optional parameter cleared to check for flag to be cleared instead of set. Use the optional parameter wait to wait until the flag is set or cleared. If not waiting the action returns immediately with BTResult.success if the flag is set otherwise BTResult.failure. If waiting the action keeps running until the flags becomes set or cleared then returns BTResult.success. A flag that has not been used so far is in cleared state. Use the optional parameter reset to toggle the flag if condition is finished. Hence if reset is used and the flag is set it is reset. This can be used for waiting and not waiting.

This is an example of using this action to check if a flag is set right now:

<action name='flags.check'>
  <parameter name='flag'>arrived at target</parameter>
</action>

This is an example of using this action to check if a flag is cleared right now:

<action name='flags.check'>
  <parameter name='flag'>arrived at target</parameter>
  <parameter name='cleared'/>
</action>

This is an example of using this action waiting until the flag is set:

<action name='flags.check' id='waiting'>
  <parameter name='flag'>arrived at target</parameter>
  <parameter name='wait'/>
</action>

This is an example of using this action waiting until the flag is set and then clear it:

<action name='flags.check' id='waiting'>
  <parameter name='flag'>arrived at target</parameter>
  <parameter name='wait'>
  <parameter name='reset'>
</action>

Behavior Tree Conditions

This behavior adds these behavior tree conditions.

flags.state

Determines if flag is set. Use as parameter flag to select the flag to check. Use optional parameter flags.cleared to check if the flag is cleared instead of set.

This is an example of an action that can only run if the flag arrived at target is set:

<action name='myAction' id='doing something'>
  <parameter name='flag'>arrived at target</parameter>
  <condition>flags.state</condition>
</action>

This is an example of an action that can only run if the flag arrived at target is cleared:

<action name='myAction' id='doing something'>
  <parameter name='flag'>arrived at target</parameter>
  <parameter name='flags.cleared'/>
  <condition>flags.state</condition>
</action>

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorBehaviorTreeFlags.

Since DragonScript Module Version 1.0

Use Cases

  • Set flags in behavior tree or game scripts that can be used to track states.

Element Class Example

This example defines an element which supports setting flags in behavior trees.

class MyElement extends BehaviorElementClass
  public var ECBehaviorBehaviorTree behaviorTree
  public var ECBehaviorBehaviorTreeFlags behaviorTreeFlags
  func new()
    behaviorTree = ECBehaviorBehaviorTree.new(this)
    behaviorTreeFlags = ECBehaviorBehaviorTreeFlags.new(this, behaviorTree)
  end
end

Behavior Factory

Using element class supporting adding behaviors the behavior can be added like this:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorBehaviorTree'/>
 
  <behavior type='ECBehaviorBehaviorTreeFlags'>
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorBehaviorTreeFlags' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_behaviortreeflags.txt · Last modified: 2025/03/12 19:41 by dragonlord