Table of Contents

,

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

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

Stashable has been removed from slot.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace inventory with inventory(id).

inventory.check

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

ParameterValueDescription
countintegerCount of stashables equals integer value
count.notintegerCount of stashables does not equal integer value
count.lessintegerCount of stashables is less than integer value
count.greaterintegerCount of stashables is greater than integer value
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='inventory.check'>
    <parameter name='count.less'>3</parameter>
  </action>
  <!-- actions here run only if inventory has less than 3 stashables -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace inventory with inventory(id).

inventory.check

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

ParameterValueDescription
inventory.countintegerCount of stashables equals integer value
inventory.count.notintegerCount of stashables does not equal integer value
inventory.count.lessintegerCount of stashables is less than integer value
inventory.count.greaterintegerCount of stashables is greater than integer value

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='inventory.count.less'>3</parameter>
  <condition>inventory.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 these state machine events. If behavior has non-empty identifier replace inventory with inventory(id).

inventory.added

Stashable has been added to inventory.

inventory.removed

Stashable has been removed from slot.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

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

API Documentation

ECBehaviorInventory.

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 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'>
    <!-- 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>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorInventory' id='second'/>
</elementClass>

Live Examples