User Tools

Site Tools


dragengine:modules:dragonscript:behavior_triggered

ECBehaviorTriggered

Behavior element behavior adding trigger support.

Adds a trigger expression to the behavior element. If the trigger expression changes value notifies the behavior element or other behaviors using listeners.

The default stub property name for the trigger expression is trigger if ID is empty or {id}.trigger if the ID is not empty. The stub property name can be changed which is typically done by ECBehavior using ECBehaviorTriggered in a composed way.

The initial state of the element is false. If the element is added to the game world notifyListeners() is only called if the trigger expression is true at this time.

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

The default stub property name for the trigger expression is trigger if ID is empty or {id}.trigger if the ID is not empty. The stub property name can be changed which is typically done by ECBehavior using ECBehaviorTriggered in a composed way.

Events

triggerExpressionTrue

Trigger expression changed to true.

triggerExpressionFalse

Trigger expression changed to false.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorTriggered.

Since DragonScript Module Version 1.0

Use Cases

  • Add trigger to element.

Element Class Example

This example defines an element which has a trigger.

class MyElement extends BehaviorElementClass
  public var ECBehaviorTriggered triggered
  func new()
    triggered = ECBehaviorTriggered.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='ECBehaviorTriggered'>
    <!-- optional: use BaseGameApp trigger table. game can add more supported values.
                   default is 'default' -->
    <string name='triggerTable'>default</string>
 
    <!-- optional: name of trigger property. default is 'trigger' or 'trigger(id)'
                   depending if id is empty string or not. -->
    <string name='propertyName'>trigger</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorTriggered' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_triggered.txt · Last modified: 2025/03/13 17:17 by dragonlord