User Tools

Site Tools


dragengine:modules:dragonscript:behavior_timer

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.

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>
 
    <!-- 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.txt · Last modified: 2025/03/13 17:16 by dragonlord