Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorInteractionElement

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 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.

ParameterValueDescription
interactstringInteract 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.parametersstringOptional parameters to use with interaction.
assignstringAssign stored interaction element to another ECBehaviorInteractionElement with identifier value
clearstringClear stored interaction element

This is an example of using this action:

<action name='interactionElement.update'>
  <parameter name='interact'>frob</parameter>
</action>

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).

ParameterValueDescription
settrue, falseInteraction element is stored
interact.namestringName of interaction
interact.hastrue, falseInteraction element is stored and interaction with name interaction.name is present
interact.querytrue, falseInteract 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.parametersstringOptional 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:

<sequence>
  <action name='interactionElement.check'>
    <parameter name='interact.query'>true</parameter>
    <parameter name='interact.name'>limitedUse.notEmpty</parameter>
  </action>
  <!-- actions here run only if interaction element is present and has uses left -->
</sequence>

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.

ParameterValueDescription
interactionElement.settrue, falseInteraction element is stored
interactionElement.interact.namestringName of interaction
interactionElement.interact.hastrue, falseInteraction element is stored and interaction with name interaction.name is present
interactionElement.interact.querytrue, falseInteract 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.parametersstringOptional parameters to use with interaction.query

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='interactionElement.interact.query'>true</parameter>
  <parameter name='interactionElement.interact.name'>limitedUse.notEmpty</parameter>
  <condition>interactionElement.check</condition>
</action>

State Machine Actions

Same as Behavior Tree Actions.

State Machine Conditions

Same as Behavior Tree Conditions.

State Machine Events

This behavior sends no state machine events.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorInteractionElement.

Since DragonScript Module Version 1.26

Use Cases

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:

<?xml version='1.0' encoding='UTF-8'?>
<elementClass name='MyClass' class='GenericBehaviorElement'>
  <behavior type='ECBehaviorInteractionElement'>
    <!-- optional: add behavior trees. default adds all behavior trees. -->
    <list name='behaviorTrees'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
 
    <!-- optional: add state machines. default adds all state machines. -->
    <list name='stateMachines'>
      <string/> <!-- add behavior with empty identifier -->
      <string>default</string> <!-- add behavior with 'default' identifier -->
    </list>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorInteractionElement' id='second'/>
</elementClass>

Live Examples