{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorTriggered**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== 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.
Optionally a synchronized trigger can be specified. If set users of this trigger should use the synchronized trigger instead of this trigger. This allows setting a single trigger expression in an element stub to affect multiple triggers in the same element class.
====== 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.
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present. Replace ''trigger'' by the value of ''propertyName'' if used.
===== trigger.check =====
Check one or more triggered trigger parameters. Action succeeds if all parameter value matches their respective triggered trigger parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a triggered trigger parameter matches (or not).
^Parameter^Value^Description^
|state|''true'', ''false''|Trigger expression evaluates to true or false|
|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:
true
====== Behavior Tree Conditions ======
This behavior adds these behavior tree conditions if behavior tree is present. Replace ''trigger'' by the value of ''propertyName'' if used.
===== trigger.check =====
Check one or more triggered trigger parameters. Conditions returns true if all parameter value match their respective triggered trigger parameter. This condition is typically used to run an action or sequence of actions as long as triggered trigger conditions are true.
^Parameter^Value^Description^
|triggered.state|''true'', ''false''|Trigger expression triggereds to true or false|
This is an example of using this condition:
true
triggered.check
====== State Machine Actions ======
Same as [[#behavior_tree_actions|Behavior Tree Actions]].
====== State Machine Conditions ======
Same as [[#behavior_tree_conditions|Behavior Tree Conditions]].
====== State Machine Events ======
This behavior sends these state machine events. Replace ''trigger'' by the value of ''propertyName'' if used.
===== trigger.true =====
Trigger expression changed to true.
===== trigger.false =====
Trigger expression changed to false.
====== Required Behaviors ======
This behavior requires no other behaviors.
====== Optional Behaviors ======
* [[behavior_behaviortree|ECBehaviorBehaviorTree]]: Add actions and conditions for behavior trees to use.
* [[behavior_statemachine|ECBehaviorStateMachine]]: Add actions and conditions for state machine to use and events to send to the state machine.
====== Persistency ======
This behavior does not required element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorTriggered.html,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:
default
trigger
other
second
second
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]