User Tools

Site Tools


dragengine:modules:dragonscript:behavior_stashable

ECBehaviorStashable

Behavior element behavior adding support for elements to be placed in ECBehaviorInventory.

Instance Counts

This behavior can be used only once on an element.

Element Class Properties

Element class properties have the prefix stashable. .

image

Set image to display in inventory screens.

  • Full name: stashable.image
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.webp, *.png, *.jpg (all image modules)
  • Example (*.deeclass)
    <string name='stashable.image'>inventory.webp</string>

video

Set video to display in inventory screens.

  • Full name: stashable.video
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.webm (all video modules)
  • Example (*.deeclass)
    <string name='stashable.video'>inventory.webm</string>

name

Set name to display in inventory screens.

  • Full name: stashable.name
  • Type: unicode string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='stashable.name'>Cool Tool</string>

description

Set description to display in inventory screens.

  • Full name: stashable.description
  • Type: unicode string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='stashable.description'>A cool tool every adventurer needs.</string>

Events

addedToInventory

Stashable has been added to inventory.

removedFromInventory

Stashable has been remove from inventory.

Behavior Tree Actions

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

stashable.remove

Remove stashable from inventory if located in one.

ParameterValueDescription
dispose If present dispose of the stashable after removing it from the inventory, no matter if present in one or not

This is an example of using this action:

<action name='stashable.remove'>
  <parameter name='dispose'>true</parameter>
</action>

stashable.check

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

ParameterValueDescription
stashedtrue, falseStashable is located in an inventory
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='stashable.check'>
    <parameter name='stashed'>true</parameter>
  </action>
  <!-- actions here run only if stashable is located in an inventory -->
</sequence>

Behavior Tree Conditions

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

stashable.check

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

ParameterValueDescription
stashable.stashedtrue, falseStashable is located in an inventory

This is an example of using this condition:

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

State Machine Actions

State Machine Conditions

State Machine Events

This behavior sends these state machine events.

stashable.added

Stashable has been added to inventory.

stashable.removed

Stashable has been removed from slot.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorStashable.

Since DragonScript Module Version 1.0

Use Cases

Element Class Example

This example defines an element which contains a resources.

class MyElement extends BehaviorElementClass
  public var ECBehaviorStashable stashable
  func new()
    stashable = ECBehaviorStashable.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='ECBehaviorStashable'>
    <!-- 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'>Cool Tool</string>
  </behavior>
</elementClass>

Live Examples

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