This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| dragengine:modules:dragonscript:behavior_timers [2026/10/12 12:02] – removed - external edit (Unknown date) 127.0.0.1 | dragengine:modules:dragonscript:behavior_timers [2026/10/12 12:03] (current) – dragonlord | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | {{tag> | ||
| + | <WRAP youarehere> | ||
| + | [[: | ||
| + | </ | ||
| + | |||
| + | * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] | ||
| + | * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] | ||
| + | |||
| + | ====== ECBehaviorTimers ====== | ||
| + | |||
| + | Behavior element behavior adding timer support to behavior trees and state machines. | ||
| + | |||
| + | Adds actions, conditions and events allowing behavior trees and state machines to start, stop and wait for multiple independent named timers. Timers count down during think updates. A timer has elapsed once its remaining time reaches 0. Timers are persisted together with the element. | ||
| + | |||
| + | ====== Instance Counts ====== | ||
| + | |||
| + | This behavior can be added only once to an element class. | ||
| + | |||
| + | ====== Element Class Properties ====== | ||
| + | |||
| + | This behavior has no element class properties. | ||
| + | |||
| + | ====== Behavior Tree Actions ====== | ||
| + | |||
| + | This behavior adds these behavior tree actions if behavior tree is present. | ||
| + | |||
| + | ===== timers.update ===== | ||
| + | |||
| + | Start or stop named timers. Action always succeeds. | ||
| + | |||
| + | ^Parameter^Value^Description^ | ||
| + | |start|string|Start named timer. The timer is added if absent. If the timer is already present it is restarted with the new timeout.| | ||
| + | |timeout|0 or larger|Seconds until the timer elapses. Used with '' | ||
| + | |timeout.lower|0 or larger|Minimum seconds of random timeout. Used with '' | ||
| + | |timeout.upper|0 or larger|Maximum seconds of random timeout. Used with '' | ||
| + | |stop|string|Stop named timer.| | ||
| + | |||
| + | This is an example of starting a timer: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is an example of starting a timer using random timeout: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is an example of stopping a timer: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== timers.check ===== | ||
| + | |||
| + | Check one or more timer parameters. Not existing timers are considered stopped. Action succeeds if all parameter values match their respective timer state otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a timer condition matches (or not). | ||
| + | |||
| + | ^Parameter^Value^Description^ | ||
| + | |timer|string|Name of the timer to check.| | ||
| + | |running|'' | ||
| + | |remaining.less|0 or larger|Remaining seconds is less than value.| | ||
| + | |remaining.greater|0 or larger|Remaining seconds is greater than value.| | ||
| + | |wait| |If present action returns BTResult.running instead of BTResult.failed to wait until the checks are all fulfilled.| | ||
| + | |||
| + | This is an example of checking if a timer is running: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | This is an example of waiting until a timer has elapsed: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== Behavior Tree Conditions ====== | ||
| + | |||
| + | This behavior adds these behavior tree conditions if behavior tree is present. | ||
| + | |||
| + | ===== timers.check ===== | ||
| + | |||
| + | Check one or more timer parameters. Condition returns true if all parameter values match their respective timer state. This condition is typically used to run an action or sequence of actions as long as timer conditions are true. | ||
| + | |||
| + | ^Parameter^Value^Description^ | ||
| + | |timers.timer|string|Name of the timer to check.| | ||
| + | |timers.running|'' | ||
| + | |timers.remaining.less|0 or larger|Remaining seconds is less than value.| | ||
| + | |timers.remaining.greater|0 or larger|Remaining seconds is greater than value.| | ||
| + | |||
| + | This is an example of using this condition: | ||
| + | <code xml> | ||
| + | <action name=' | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== State Machine Actions ====== | ||
| + | |||
| + | Same as [[# | ||
| + | |||
| + | ====== State Machine Conditions ====== | ||
| + | |||
| + | Same as [[# | ||
| + | |||
| + | ====== State Machine Events ====== | ||
| + | |||
| + | This behavior sends these state machine events. | ||
| + | |||
| + | ===== timers.elapsed:< | ||
| + | |||
| + | Timer named '' | ||
| + | |||
| + | This is an example of a transition that runs if the timer " | ||
| + | <code xml> | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== Required Behaviors ====== | ||
| + | |||
| + | This behavior requires no other behaviors. | ||
| + | |||
| + | ====== Optional Behaviors ====== | ||
| + | |||
| + | * [[behavior_behaviortree|ECBehaviorBehaviorTree]]: | ||
| + | * [[behavior_statemachine|ECBehaviorStateMachine]]: | ||
| + | |||
| + | ====== Persistency ====== | ||
| + | |||
| + | This behavior does support element class to be persistable (setPersistable). Running timers are persisted. | ||
| + | |||
| + | ====== API Documentation ====== | ||
| + | |||
| + | # | ||
| + | |||
| + | Since DragonScript Module Version '' | ||
| + | |||
| + | ====== Use Cases ====== | ||
| + | |||
| + | * Delay an action, for example close a door a few seconds after it has been opened. | ||
| + | * Let a state machine switch state after a timeout, for example leave an idle state after some time. | ||
| + | * Add random delays using '' | ||
| + | |||
| + | ====== Element Class Example ====== | ||
| + | |||
| + | This example defines an element which contains timers. | ||
| + | |||
| + | < | ||
| + | class MyElement extends BehaviorElementClass | ||
| + | public var ECBehaviorTimers timers | ||
| + | func new() | ||
| + | timers = ECBehaviorTimers.new(this) | ||
| + | end | ||
| + | end | ||
| + | </ | ||
| + | |||
| + | ====== Behavior Factory ====== | ||
| + | |||
| + | Using element class supporting adding behaviors the behavior can be added like this: | ||
| + | <code xml> | ||
| + | <?xml version=' | ||
| + | < | ||
| + | < | ||
| + | <!-- optional: add behavior trees. default adds all behavior trees. --> | ||
| + | <list name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <!-- optional: add state machines. default adds all state machines. --> | ||
| + | <list name=' | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== Live Examples ====== | ||
| + | |||
| + | * [[https:// | ||