{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorTimer**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorTimer ======
Behavior element behavior timer trigger target.
Fires or resets trigger target after timeout after evaluation state of trigger expression changes to true.
====== Instance Counts ======
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 ======
Element class properties have the prefix ''timer.'' or ''timer({id}).'' if id is not empty.
===== trigger =====
Trigger to start timer.
* Full name: ''timer.trigger'' or ''timer({id}).trigger''
* Type: string
* Default Value: empty string
* Example (*.deeclass) @switchOnVent & @powerEnabled
===== target =====
Fires target if timer elapses.
* Full name: ''timer.target'' or ''timer({id}).target''
* Type: string
* Default Value: empty string
* Example (*.deeclass) ventOn
===== timeout =====
Timeout in seconds to wait after trigger evaluiates to true before firing target.
* Full name: ''timer.timeout'' or ''timer({id}).timeout''
* Type: float
* Default Value: ''0''
* Restriction: At least ''0''
* Example (*.deeclass) 1
===== timeoutSpread =====
Random time in seconds (between 0 and ''timeoutSpread'' seconds) to add to timeout.
* Full name: ''timer.timeoutSpread'' or ''timer({id}).timeoutSpread''
* Type: float
* Default Value: ''0''
* Restriction: At least ''0''
* Example (*.deeclass) 1
===== timeoutRearm =====
Rearm timer after timeout if trigger still evaluates to true. Hence the timer is repeating until the trigger evaluates to false.
* Full name: ''timer.timeoutRearm'' or ''timer({id}).timeoutRearm''
* Type: boolean
* Default Value: ''false''
* Example (*.deeclass) true
===== fireOnTimeout =====
Fire target on timeout. If set to ''false'' resets the target instead.
* Full name: ''timer.fireOnTimeout'' or ''timer({id}).fireOnTimeout''
* Type: boolean
* Default Value: ''true''
* Example (*.deeclass) false
===== startActivated =====
Timer is activated after creating the element no matter if trigger evaluates to true at this point in time.
* Full name: ''timer.startActivated'' or ''timer({id}).startActivated''
* Type: boolean
* Default Value: ''false''
* Example (*.deeclass) true
===== fullReset =====
If ''fireOnTimeout'' is ''false'' the target is full reset instead of just reset.
* Full name: ''timer.fullReset'' or ''timer({id}).fullReset''
* Type: boolean
* Default Value: ''false''
* Example (*.deeclass) true
===== pulse =====
Pulse target instead of firing it.
* Full name: ''evaluate.pulse'' or ''evaluate({id}).pulse''
* Type: boolean
* Default Value: ''false''
* Example (*.deeclass) true
===== cancelOnReset =====
If trigger evaluates to false while the timeout is running cancel the timeout.
* Full name: ''evaluate.cancelOnReset'' or ''evaluate({id}).cancelOnReset''
* Type: boolean
* Default Value: ''false''
* Example (*.deeclass) true
====== Events ======
===== timerStarted =====
Timer started.
===== timerElapsed =====
Timer elapsed.
===== timerCancelled =====
Timer cancelled.
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''timer'' with ''timer(id)''.
===== timer.set =====
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''|
* ''arm'': Arm timer if not running
* ''cancel'': Cancel timer if running
* ''rearm'': Cancel timer then arm it
* ''timeout'': Cancel timer then trigger timeout
|
This is an example of using this action:
reset
rearm
===== timer.check =====
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|
|wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled|
This is an example of using this action:
true
3
====== Behavior Tree Conditions ======
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''timer'' with ''timer(id)''.
===== timer.check =====
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:
true
3
timer.check
====== State Machine Actions ======
Same as [[#behavior_tree_actions|Behavior Tree Actions]].
====== State Machine Conditions ======
Same as [[#behavior_tree_conditions|Behavior Tree Conditions]].
====== State Machine Events ======
This behavior sends these state machine events. If behavior has non-empty identifier replace ''timer'' with ''timer(id)''.
===== timer.started =====
Timer started.
===== timer.elapsed =====
Timer elapsed.
===== timer.cancelled =====
Timer cancelled.
====== Required Behaviors ======
This behavior requires no other behaviors.
====== Optional Behaviors ======
* [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use.
* [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorTimer.html,ECBehaviorTimer~@#.
Since DragonScript Module Version ''1.0''
====== Use Cases ======
* Fire timer after a timeout after trigger evaluates to true.
* Reset triggers that have been fired before.
* Full reset triggers to restart a task from the beginning.
====== Element Class Example ======
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
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
default
other
second
second
ventOn
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]