This is an old revision of the document!
Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorTimer
Behavior element behavior timer trigger target.
Fires or resets trigger target after timeout after evaluation state of trigger expression changes to true.
This behavior can be used multiple times on an element to add multiple triggers. Use the behavior identifier to tell them apart.
Element class properties have the prefix timer.
or timer({id}).
if id is not empty.
Trigger to start timer.
timer.trigger
or timer({id}).trigger
<string name='timer.trigger'>@switchOnVent & @powerEnabled</string>
Fires target if timer elapses.
timer.target
or timer({id}).target
<string name='timer.target'>ventOn</string>
Timeout in seconds to wait after trigger evaluiates to true before firing target.
timer.timeout
or timer({id}).timeout
0
0
<float name='timer.timeout'>1</float>
Random time in seconds (between 0 and timeoutSpread
seconds) to add to timeout.
timer.timeoutSpread
or timer({id}).timeoutSpread
0
0
<float name='timer.timeoutSpread'>1</float>
Rearm timer after timeout if trigger still evaluates to true. Hence the timer is repeating until the trigger evaluates to false.
timer.timeoutRearm
or timer({id}).timeoutRearm
false
<boolean name='timer.timeoutRearm'>true</boolean>
Fire target on timeout. If set to false
resets the target instead.
timer.fireOnTimeout
or timer({id}).fireOnTimeout
true
<boolean name='timer.fireOnTimeout'>false</boolean>
Timer is activated after creating the element no matter if trigger evaluates to true at this point in time.
timer.startActivated
or timer({id}).startActivated
false
<boolean name='timer.startActivated'>true</boolean>
If fireOnTimeout
is false
the target is full reset instead of just reset.
timer.fullReset
or timer({id}).fullReset
false
<boolean name='timer.fullReset'>true</boolean>
Pulse target instead of firing it.
evaluate.pulse
or evaluate({id}).pulse
false
<boolean name='evaluate.pulse'>true</boolean>
If trigger evaluates to false while the timeout is running cancel the timeout.
evaluate.cancelOnReset
or evaluate({id}).cancelOnReset
false
<boolean name='evaluate.cancelOnReset'>true</boolean>
Timer started.
Timer elapsed.
Timer cancelled.
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace timer
with timer(id)
.
Set one or more timer trigger parameters.
Parameter | Value | Description |
---|---|---|
target | fire , reset , fullReset | Fire, reset or full reset target |
timer | arm , cancel , rearm , timeout |
|
This is an example of using this action:
<action name='timer.set'> <parameter name='target'>reset</parameter> <parameter name='timer'>rearm</parameter> </action>
Check one or more timer trigger parameters. Action succeeds if all parameter value matches their respective timer trigger parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a timer trigger parameter matches (or not).
Parameter | Value | Description |
---|---|---|
trigger | true , false | Trigger expression evaluates to true or false |
target.fired | true , false | Target is in fired or reset state |
target.everFired | true , false | Target has been fired at least once or never |
running | true , false | Timer is running |
remaining.less | float | Remaining timer time is less than value in seconds |
remaining.greater | float | Remaining timer time is greater than value in seconds |
This is an example of using this action:
<sequence> <action name='timer.check'> <parameter name='running'>true</parameter> <parameter name='remaining.less'>3</parameter> </action> <!-- actions here run only if timer is running with less than 3 seconds remaining --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace timer
with timer(id)
.
Check one or more timer trigger parameters. Conditions returns true if all parameter value match their respective timer trigger parameter. This condition is typically used to run an action or sequence of actions as long as timer trigger conditions are true.
Parameter | Value | Description |
---|---|---|
timer.trigger | true , false | Trigger expression timers to true or false |
timer.target.fired | true , false | Target is in fired or reset state |
timer.target.everFired | true , false | Target has been fired at least once or never |
timer.running | true , false | Timer is running |
timer.remaining.less | float | Remaining timer time is less than value in seconds |
timer.remaining.greater | float | Remaining timer time is greater than value in seconds |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='timer.running'>true</parameter> <parameter name='timer.remaining.less'>3</parameter> <condition>timer.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events. If behavior has non-empty identifier replace timer
with timer(id)
.
Timer started.
Timer elapsed.
Timer cancelled.
This behavior requires no other behaviors.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which can timer fire a target.
class MyElement extends BehaviorElementClass public var ECBehaviorTimer timer func new() timer = ECBehaviorTimer.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='ECBehaviorTimer'> <!-- optional: use BaseGameApp trigger table. game can add more supported values. default is 'default' --> <string name='triggerTable'>default</string> <!-- optional: identifier of ECBehaviorTriggered to synchronize with or empty string to not synchronize. default is empty string. --> <string name='trigger.synchronize'>other</string> <!-- optional: use behavior tree with id instead of empty string --> <string name='behaviorTree'>second</string> <!-- optional: use state machine with id instead of empty string --> <string name='stateMachine'>second</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.target'>ventOn</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorTimer' id='second'/> </elementClass>