This is an old revision of the document!
Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorToggle
Behavior element behavior toggling trigger target.
Toggles trigger target between fired and reset state whenever evaluation state of trigger expression changes to true.
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 have the prefix toggle.
or toggle({id}).
if id is not empty.
Trigger to evaluate.
toggle.trigger
or toggle({id}).trigger
<string name='toggle.trigger'>@switchOnVent & @powerEnabled</string>
Switches target between fired and reset state whenever trigger evaluates to true.
toggle.target
or toggle({id}).target
<string name='toggle.target'>ventOn</string>
Fires target when behavior is created if not fired yet.
toggle.startActivated
or toggle({id}).startActivated
false
<boolean name='toggle.startActivated'>true</boolean>
Trigger target toggled.
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace toggle
with toggle(id)
.
Set one or more toggle trigger parameters.
Parameter | Value | Description |
---|---|---|
target | fire , reset , fullReset , toggle | Fire, reset, full reset or toggle target |
This is an example of using this action:
<action name='toggle.set'> <parameter name='target'>toggle</parameter> </action>
Check one or more toggle trigger parameters. Action succeeds if all parameter value matches their respective toggle trigger parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a toggle trigger parameter matches (or not).
Parameter | Value | Description |
---|---|---|
trigger | true , false | Trigger expression evaluates to true or false |
target.fired | true , false | Target is in fired or reset state |
target.everFired | true , false | Target has been fired at least once or never |
This is an example of using this action:
<sequence> <action name='toggle.check'> <parameter name='target.fired'>false</parameter> <parameter name='target.everFired'>false</parameter> </action> <!-- actions here run only if target is in reset state and has been never fired yet --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace toggle
with toggle(id)
.
Check one or more toggle trigger parameters. Conditions returns true if all parameter value match their respective toggle trigger parameter. This condition is typically used to run an action or sequence of actions as long as toggle trigger conditions are true.
Parameter | Value | Description |
---|---|---|
toggle.trigger | true , false | Trigger expression toggles to true or false |
toggle.target.fired | true , false | Target is in fired or reset state |
toggle.target.everFired | true , false | Target has been fired at least once or never |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='target.fired'>false</parameter> <parameter name='target.everFired'>false</parameter> <condition>toggle.check</condition> </action>
This behavior requires no other behaviors.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which toggles trigger.
class MyElement extends BehaviorElementClass public var ECBehaviorToggle toggle func new() toggle = ECBehaviorToggle.new(this) end end
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> <!-- 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='.name'>Color 1</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorToggle' id='second'/> </elementClass>