{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorBehaviorTreeTimer** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== ECBehaviorBehaviorTreeTimer ====== Behavior element behavior adding timer support to behavior tree support. Behavior adds behavior tree actions and conditions to an [[behavior_behaviortree|ECBehaviorBehaviorTree]] allowing behavior trees to start and wait for multiple independent timers. ====== Instance Counts ====== 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 ====== Element class properties have the prefix ''behaviorTreeTimers.'' or ''behaviorTreeTimers({id}).'' if id is not empty. ====== Events ====== This behavior has no events. ====== Behavior Tree Actions ====== This behavior adds these behavior tree actions. ===== timer.start ===== 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: 1.5 myTimer This is an example of using this action with random timeout: 1.5 2.5 myTimer ===== timer.stop ===== 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: myTimer ===== timer.wait ===== 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: myTimer ====== Behavior Tree Conditions ====== This behavior adds these behavior tree conditions. ===== timer.running ===== 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: myTimer timer.running ===== timer.finished ===== 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: myTimer timer.finished ====== Required Behaviors ====== * [[behavior_behaviortree|ECBehaviorBehaviorTree]] ====== Optional Behaviors ====== This behavior does not support optional behaviors. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorBehaviorTreeTimer.html,ECBehaviorBehaviorTreeTimer~@#. Since DragonScript Module Version ''1.0'' ====== Use Cases ====== * Allow timers to be used in behavior trees. ====== Element Class Example ====== 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 ====== Behavior Factory ====== Using element class supporting adding behaviors the behavior can be added like this: second value ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]