User Tools

Site Tools


dragengine:modules:dragonscript:behavior_toggle

ECBehaviorToggle

Behavior element behavior toggling trigger target.

Toggles trigger target between fired and reset state whenever 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 toggle. or toggle({id}). if id is not empty.

trigger

Trigger to evaluate.

  • Full name: toggle.trigger or toggle({id}).trigger
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='toggle.trigger'>@switchOnVent & @powerEnabled</string>

target

Switches target between fired and reset state whenever trigger evaluates to true.

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

startActivated

Fires target when behavior is created if not fired yet.

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

Events

toggled

Trigger target toggled.

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

ECBehaviorToggle.

Since DragonScript Module Version 1.0

Use Cases

  • Toggle target if trigger evaluates to true.

Element Class Example

This example defines an element which toggles trigger.

class MyElement extends BehaviorElementClass
  public var ECBehaviorToggle toggle
  func new()
    toggle = ECBehaviorToggle.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='ECBehaviorToggle'>
    <!-- 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='.name'>Color 1</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorToggle' id='second'/>
</elementClass>

Live Examples

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