This is an old revision of the document!
Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorAttachable
Behavior element behavior adding support to be attached to an ECBehaviorAttachSlot.
While ECBehaviorAttachToParent behavior allows to attach objects by using the IGDE World Editor the ECBehaviorAttachable behavior allows to attach objects at runtime into attachment slots provided by ECBehaviorAttachSlot.
This behavior knows how to attach to ECBehaviorAttachSlot containing an ECBehaviorCollider.
This behavior can be used only once on an element.
Element class properties have the prefix attachable.
.
This behavior has these events:
Attachable has been attached to slot.
Attachable has been removed from slot.
This behavior adds these behavior tree actions if behavior tree is present.
Detach element from attach slot if attached to an attach slot.
Parameter | Value | Description |
---|---|---|
dispose | If present element is disposed after detaching, even if not attached before. Action returns BTResult.running to stop the behavior tree. |
This is an example of using this action:
<action name='attachable.detach'> <parameter name='dispose'/> </action>
Check one or more attachable parameters. Action succeeds if all parameter value matches their respective attachable parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a attachable parameter matches (or not).
Parameter | Value | Description |
---|---|---|
attached | true , false | Element is attached to an attach slot or not |
This is an example of using this action:
<sequence> <action name='attachable.check'> <parameter name='attached'>true</parameter> </action> <!-- actions here run only if element is attached to a slot --> </sequence>
This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace attachable
with attachable(id)
.
Check one or more attachable parameters. Conditions returns true if all parameter value match their respective attachable parameter. This condition is typically used to run an action or sequence of actions as long as attachable conditions are true.
Parameter | Value | Description |
---|---|---|
attachable.attached | true , false | Element is attached to an attach slot or not |
This is an example of using this condition:
<action name='myAction' id='doing something'> <parameter name='attachable.attached'>true</parameter> <condition>attachable.check</condition> </action>
Same as Behavior Tree Actions.
Same as Behavior Tree Conditions.
This behavior sends these state machine events..
===== attachable.attached =====
Attachable has been attached to slot.
===== attachable.detached =====
Attachable has been removed from slot.
====== Required Behaviors ======
* ECBehaviorCollider
====== Optional Behaviors ======
* ECBehaviorBehaviorTree: Add actions and conditions for behavior trees to use.
* ECBehaviorStateMachine: Add actions and conditions for state machine to use and events to send to the state machine.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable).
====== API Documentation ======
ECBehaviorAttachable.
Since DragonScript Module Version
1.0''
This example defines an element which can be attached to ECBehaviorAttachSlot.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorAttachable attachable func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) attachable = ECBehaviorAttachable.new(this, collider) end end
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='ECBehaviorAttachable'> <!-- 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>