Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorBehaviorTreeTimer
Behavior element behavior adding timer support to behavior tree support.
Behavior adds behavior tree actions and conditions to an ECBehaviorBehaviorTree allowing behavior trees to start and wait for multiple independent timers.
This behavior can be added multiple times to an element for each ECBehaviorBehaviorTree. Each instance creates an own set of behavior tree action and conditions and timers.
Element class properties have the prefix behaviorTreeTimers.
or behaviorTreeTimers({id}).
if id is not empty.
This behavior has no events.
This behavior adds these behavior tree actions.
Starts a timer. As parameter use timeout
to set the seconds until the timer elapses or timeout.lower
and timeout.upper
to randomly select seconds between a lower and upper limit (inclusive). Optionally use parameter timer
to select the timer. timer
is a string identifier you can freely choose. If absent empty string is used as timer identifier. The timer is created if absent. This action immediately returns and does not require a rule identifier.
This is an example of using this action:
<action name='timer.start'> <parameter name='timeout'>1.5</parameter> <parameter name='timer'>myTimer</parameter> </action>
This is an example of using this action with random timeout:
<action name='timer.start'> <parameter name='timeout.lower'>1.5</parameter> <parameter name='timeout.upper'>2.5</parameter> <parameter name='timer'>myTimer</parameter> </action>
Stops a timer. Optionally as parameter use timer
to select the timer matching an identifier used in a previous action timer.start
. This action immediately returns and does not require a rule identifier.
This is an example of using this action:
<action name='timer.stop'> <parameter name='timer'>myTimer</parameter> </action>
Waits for a timer to elapse. Optionally as parameter use timer
to select the timer matching an identifier used in a previous action timer.start
. The action keeps running until the timer elapsed. If the timer is absent the action immediately returns.
This is an example of using this action:
<action name='timer.stop' id='waiting'> <parameter name='timer'>myTimer</parameter> </action>
This behavior adds these behavior tree conditions.
Determines if timer is running and has not elapsed yet. Optionally as parameter use timer
to select the timer matching an identifier used in a previous action timer.start
.
This is an example of an action that can only run if the timer myTimer
is running:
<action name='myAction' id='doing something'> <parameter name='timer'>myTimer</parameter> <condition>timer.running</condition> </action>
Determines if timer is not running or has elapsed. Optionally as parameter use timer
to select the timer matching an identifier used in a previous action timer.start
.
This is an example of an action that can only run if the timer myTimer
is running:
<action name='myAction' id='doing something'> <parameter name='timer'>myTimer</parameter> <condition>timer.finished</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 can use timers in behavior trees.
class MyElement extends BehaviorElementClass public var ECBehaviorBehaviorTree behaviorTree public var ECBehaviorBehaviorTreeTimer behaviorTreeTimer func new() behaviorTree = ECBehaviorBehaviorTree.new(this) behaviorTreeTimer = ECBehaviorBehaviorTreeTimer.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='ECBehaviorBehaviorTreeTimer'> <!-- 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='ECBehaviorBehaviorTreeTimer' id='second'/> </elementClass>