{{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]] >> **ECBehaviorInteractionElement**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorInteractionElement ======
Behavior element behavior adding support to store an interaction element.
This behavior allows to store for a longer time an element found by another behavior. For example [[behavior_lookat|ECBehaviorLookAt]] is able to locate an element. By storing this element in this behavior another behavior, state machine or behavior tree can use this found element to interact with it.
This behavior is able to persist and restore the element. This is though only possible as long as the element is part of a game world. Hence while leaving a game world the interact element is cleared. It is also possible the element is stored longer than it exists in the game world. After loading it is thus possible the interact element can not be resolved. Behaviors, state machines and behavior trees using this interact element behavior have to be prepared for the interact element to be null after loading.
====== Instance Counts ======
This behavior can be used multiple times on an element to add multiple interaction elements to mainpulate. Use the behavior identifier to tell them apart.
====== Element Class Properties ======
Element class properties have the prefix ''interactionElement.'' or ''interactionElement({id}).'' if id is not empty.
====== Events ======
This behavior supports no events:
====== Behavior Tree Actions ======
This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace ''interactionElement'' with ''interactionElement(id)''.
===== interactionElement.update =====
Update interaction element.
^Parameter^Value^Description^
|interact|string|Interact with stored element. If element is absent action fails. Runs interaction with name value. If interaction with name value is absent fails action. If interaction returns false fails action. Otherwise action succeeds.|
|interact.parameters|string|Optional parameters to use with ''interaction''.|
|assign|string|Assign stored interaction element to another ECBehaviorInteractionElement with identifier value|
|clear|string|Clear stored interaction element|
This is an example of using this action:
frob
===== interactionElement.check =====
Check one or more interaction element parameters. Action succeeds if all parameter value matches their respective interaction element parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a interaction element parameter matches (or not).
^Parameter^Value^Description^
|set|''true'', ''false''|Interaction element is stored|
|interact.name|string|Name of interaction|
|interact.has|''true'', ''false''|Interaction element is stored and interaction with name ''interaction.name'' is present|
|interact.query|''true'', ''false''|Interact with stored element and test result. Condition is true if interaction element is stored, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).|
|interact.parameters|string|Optional parameters to use with ''interaction.query''.|
|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
limitedUse.notEmpty
====== Behavior Tree Conditions ======
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace ''interactionElement'' with ''interactionElement(id)''.
===== interactionElement.check =====
Check one or more interaction element parameters. Conditions returns true if all parameter value match their respective interaction element parameter. This condition is typically used to run an action or sequence of actions as long as interaction element conditions are true.
^Parameter^Value^Description^
|interactionElement.set|''true'', ''false''|Interaction element is stored|
|interactionElement.interact.name|string|Name of interaction|
|interactionElement.interact.has|''true'', ''false''|Interaction element is stored and interaction with name ''interaction.name'' is present|
|interactionElement.interact.query|''true'', ''false''|Interact with stored element and test result. Condition is true if interaction element is stored, interaction with name ''interaction.name'' is present and interaction returns true. It is recommended to use here only interactions without side effects (hence query interactions).|
|interactionElement.interact.parameters|string|Optional parameters to use with ''interaction.query''|
This is an example of using this condition:
true
limitedUse.notEmpty
interactionElement.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 no state machine events.
====== 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.
* [[behavior_conversationactor|ECBehaviorConversationActor]]: Add actions and conditions for conversation actor to use.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorInteractionElement.html,ECBehaviorInteractionElement~@#.
Since DragonScript Module Version ''1.26''
====== Use Cases ======
* Allow behavior trees and state machines to interact with elements supporting [[behavior_interaction|ECBehaviorInteraction]].
====== Element Class Example ======
This example defines an element which contains a interaction element.
class MyElement extends BehaviorElementClass
public var ECBehaviorInteractionElement interactionElement
func new()
interactionElement = ECBehaviorInteractionElement.new(this)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
default
default
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]