Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorTimer

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.

target

Fires target if timer elapses.

timeout

Timeout in seconds to wait after trigger evaluiates to true before firing target.

timeoutSpread

Random time in seconds (between 0 and timeoutSpread seconds) to add to timeout.

timeoutRearm

Rearm timer after timeout if trigger still evaluates to true. Hence the timer is repeating until the trigger evaluates to false.

fireOnTimeout

Fire target on timeout. If set to false resets the target instead.

startActivated

Timer is activated after creating the element no matter if trigger evaluates to true at this point in time.

fullReset

If fireOnTimeout is false the target is full reset instead of just reset.

pulse

Pulse target instead of firing it.

cancelOnReset

If trigger evaluates to false while the timeout is running cancel the timeout.

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='target'>reset</parameter>
  <parameter name='timer'>rearm</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
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:

<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 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.remaining.less'>3</parameter>
  <condition>timer.check</condition>
</action>

State Machine Actions

Same as Behavior Tree Actions.

State Machine Conditions

Same as 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

Persistency

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

API Documentation

ECBehaviorTimer.

Since DragonScript Module Version 1.0

Use Cases

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>
 
    <!-- optional: use behavior tree with id instead of empty string -->
    <string name='behaviorTree'>second</string>
 
    <!-- optional: use state machine with id instead of empty string -->
    <string name='stateMachine'>second</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