User Tools

Site Tools


dragengine:modules:dragonscript:behavior_timer

This is an old revision of the document!


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)
    <string name='timer.trigger'>@switchOnVent & @powerEnabled</string>

target

Fires target if timer elapses.

  • Full name: timer.target or timer({id}).target
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='timer.target'>ventOn</string>

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)
    <float name='timer.timeout'>1</float>

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)
    <float name='timer.timeoutSpread'>1</float>

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)
    <boolean name='timer.timeoutRearm'>true</boolean>

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)
    <boolean name='timer.fireOnTimeout'>false</boolean>

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)
    <boolean name='timer.startActivated'>true</boolean>

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)
    <boolean name='timer.fullReset'>true</boolean>

pulse

Pulse target instead of firing it.

  • Full name: evaluate.pulse or evaluate({id}).pulse
  • Type: boolean
  • Default Value: false
  • Example (*.deeclass)
    <boolean name='evaluate.pulse'>true</boolean>

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)
    <boolean name='evaluate.cancelOnReset'>true</boolean>

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.

ParameterValueDescription
targetfire, reset, fullResetFire, reset or full reset target
timerarm, 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:

<action name='timer.set'>
  <parameter name='enabled'>true</parameter>
</action>

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).

ParameterValueDescription
triggertrue, falseTrigger expression evaluates to true or false
target.firedtrue, falseTarget is in fired or reset state
target.everFiredtrue, falseTarget has been fired at least once or never
runningtrue, falseTimer is running
remaining.lessfloatRemaining timer time is less than value in seconds
remaining.greaterfloatRemaining 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 more less than 3 seconds remaining -->
</sequence>

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.

ParameterValueDescription
timer.triggertrue, falseTrigger expression timers to true or false
timer.target.firedtrue, falseTarget is in fired or reset state
timer.target.everFiredtrue, falseTarget has been fired at least once or never
timer.runningtrue, falseTimer is running
timer.remaining.lessfloatRemaining timer time is less than value in seconds
timer.remaining.greaterfloatRemaining 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.remainiing.less'>3</parameter>
  <condition>timer.check</condition>
</action>

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

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:

<?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>
 
    <!-- 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>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_timer.1746108253.txt.gz · Last modified: 2025/05/01 14:04 by dragonlord