Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorBTSMFlags

ECBehaviorBTSMFlags

Behavior element behavior adding flags support to behavior trees and state machines.

Adds actions, conditions and events allowing behavior trees and state machines to set, clear and check named flags. Flags are stored per element instance. Flags that are not set are considered cleared. Flags are persisted together with the element.

Instance Counts

This behavior can be added only once to an element class.

Element Class Properties

This behavior has no element class properties.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present.

flags.update

Update flags. Action always succeeds.

ParameterValueDescription
setstringSet named flag.
clearstringClear named flag.

This is an example of setting a flag:

<action name='flags.update'>
  <parameter name='set'>arrived at target</parameter>
</action>

This is an example of setting and clearing a flag in the same action:

<action name='flags.update'>
  <parameter name='set'>arrived at target</parameter>
  <parameter name='clear'>stay seated</parameter>
</action>

flags.check

Check one or more flag parameters. Action succeeds if all parameter values match their respective flag state otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a flag matches (or not).

ParameterValueDescription
flagstringFlag to check.
settrue, falseFlag is set or not.
wait If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled.
reset If present toggle the flag after the checks succeeded.

This is an example of checking if a flag is set right now:

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

This is an example of waiting until a flag is set:

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

This is an example of waiting until a flag is set and then clearing it:

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

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present.

flags.check

Check flag parameters. Condition returns true if all parameter values match their respective flag state. This condition is typically used to run an action or sequence of actions as long as flag conditions are true.

ParameterValueDescription
flags.flagstringFlag to check.
flags.settrue, falseFlag is set or not.

This is an example of using this condition:

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

State Machine Actions

Same as Behavior Tree Actions.

State Machine Conditions

Same as Behavior Tree Conditions.

State Machine Events

This behavior sends these state machine events.

flags.set:<name>

Flag named name changed from cleared to set. The name of the flag is appended to the event name.

This is an example of a transition that runs if the flag “arrived at target” has been set:

<transition event='flags.set:arrived at target' state='nextState'>
</transition>

flags.cleared:<name>

Flag named name changed from set to cleared. The name of the flag is appended to the event name.

This is an example of a transition that runs if the flag “arrived at target” has been cleared:

<transition event='flags.cleared:arrived at target' state='nextState'>
</transition>

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable). Set flags are persisted.

API Documentation

ECBehaviorBTSMFlags.

Since DragonScript Module Version 1.35

Use Cases

Element Class Example

This example defines an element which contains flags.

class MyElement extends BehaviorElementClass
  public var ECBehaviorBTSMFlags flags
  func new()
    flags = ECBehaviorBTSMFlags.new(this)
  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='ECBehaviorBTSMFlags'>
    <!-- optional: add behavior trees. default adds all behavior trees. -->
    <list name='behaviorTrees'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
 
    <!-- optional: add state machines. default adds all state machines. -->
    <list name='stateMachines'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
  </behavior>
</elementClass>

Live Examples