Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » 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.
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 have the prefix behaviorTreeFlags.
or behaviorTreeFlags({id}).
if id is not empty.
This behavior has no events.
This behavior adds these behavior tree actions.
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>
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>
This behavior adds these behavior tree conditions.
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>
This behavior does not support optional behaviors.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
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
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>