User Tools

Site Tools


dragengine:modules:dragonscript:behavior_inventory

ECBehaviorInventory

Behavior element behavior inventory support.

Adds inventory where stashable elements can be put into. The inventory does not make any assumptions about the kind of inventory nor does it impose any kind of restrictions. Game scripts and behaviors using the inventory are responsible to apply such restrictions.

Instance Counts

This behavior can be used multiple times on an element to add multiple inventories. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix inventory. or inventory({id}). if id is not empty.

Events

stashableAdded

Stashable has been added to inventory.

===== stashableRemoved ( Instance instance, ECBehaviorStashable.Instance stashable )

Stashable has been removed from slot.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorInventory.

Since DragonScript Module Version 1.0

Use Cases

  • Add inventory to actor elements can be placed in.

Element Class Example

This example defines an element which contains a resources.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    ECBehaviorInventory.new(this, "color1", "Color 1", Color.blue)
    ECBehaviorInventory.new(this, "color2", "Color 2", Color.red)
  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='ECBehaviorInventory'>
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.name'>value</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorInventory' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_inventory.txt · Last modified: 2025/03/12 21:36 by dragonlord