{{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]] >> **ECBehaviorToggle** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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) @switchOnVent & @powerEnabled ===== 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) ventOn ===== 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) true ====== Events ====== ===== toggled ===== Trigger target toggled. ====== Behavior Tree Actions ====== This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''toggle'' with ''toggle(id)''. ===== toggle.set ===== 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: toggle ===== toggle.check ===== 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| |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: false false ====== Behavior Tree Conditions ====== This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''toggle'' with ''toggle(id)''. ===== toggle.check ===== 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: false false toggle.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. If behavior has non-empty identifier replace ''toggle'' with ''toggle(id)''. ===== toggle.toggled ===== Trigger target toggled. ====== 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_1ECBehaviorToggle.html,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: default other second second Color 1 ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]