This is an old revision of the document!
Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » 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.
This behavior can be added only once to an element class.
This behavior has no element class properties.
This behavior adds these behavior tree actions if behavior tree is present.
Update flags. Action always succeeds.
| Parameter | Value | Description |
|---|---|---|
| set | string | Set named flag. |
| clear | string | Clear 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>
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).
| Parameter | Value | Description |
|---|---|---|
| flag | string | Flag to check. |
| set | true, false | Flag 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>
This behavior adds these behavior tree conditions if behavior tree is present.
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.
| Parameter | Value | Description |
|---|---|---|
| flags.flag | string | Flag to check. |
| flags.set | true, false | Flag 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>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events.
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>
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>
This behavior requires no other behaviors.
This behavior does support element class to be persistable (setPersistable). Set flags are persisted.
Since DragonScript Module Version 1.35
This example defines an element which contains flags.
class MyElement extends BehaviorElementClass
public var ECBehaviorBTSMFlags flags
func new()
flags = ECBehaviorBTSMFlags.new(this)
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='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>