User Tools

Site Tools


dragengine:modules:dragonscript:behavior_showelement

ECBehaviorShowElement

Behavior element behavior show/hide element if triggered.

If trigger evaluates to true the element is set visible and touchable others not.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix showElement..

trigger

Set trigger to show element.

  • Full name: showElement.trigger or showElement({id}).trigger
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='showElement.trigger'>@playerEnterSpot & @ghostPresent</string>

Events

This behavior has no events.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present.

showElement.set

Set one or more show element parameters.

ParameterValueDescription
showntrue,falseShow or hide element

This is an example of using this action:

<action name='showElement.set'>
  <parameter name='shown'>true</parameter>
</action>

showElement.check

Check one or more show element parameters. Action succeeds if all parameter value matches their respective show element parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a show element parameter matches (or not).

ParameterValueDescription
showntrue,falseElement is shown or hidden
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='showElement.check'>
    <parameter name='shown'>true</parameter>
  </action>
  <!-- actions here run only if show element is shown -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present.

showElement.check

Check one or more show element parameters. Conditions returns true if all parameter value match their respective show element parameter. This condition is typically used to run an action or sequence of actions as long as show element conditions are true.

ParameterValueDescription
showElement.showntrue,falseElement is shown or hidden

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='showElement.shown'>true</parameter>
  <condition>showElement.check</condition>
</action>

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends these state machine events.

showElement.shown

Element has been shown.

showElement.hidden

Element has been hidden.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorShowElement.

Since DragonScript Module Version 1.19

Use Cases

  • Make element appear if player touches a trigger.

Element Class Example

This example defines an element which contains a resources.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorShowElement showElement
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    showElement = ECBehaviorShowElement.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='ECBehaviorComponent'/>
  <behavior type='ECBehaviorCollider'/>
 
  <behavior type='ECBehaviorShowElement'>
    <!-- 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'>value</string>
  </behavior>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_showelement.txt · Last modified: 2025/05/04 13:43 by dragonlord