{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorComposed**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorComposed ======
Behavior for element allowing to create and add child elements.
This behavior is useful to create element classes which automatically create and attach child elements without using the world editor.
This behavior defines a list of element classes to use. For each element class an optional list of property values can be defined that are used to create an instance of this class.
====== Instance Counts ======
This behavior can be used only once on an element.
====== Element Class Properties ======
Element class properties have the prefix ''composed.''.
===== children =====
Set child elements to create. This is a list of map entries for each child element. Children are created in the order they are defined. The map entry requires at least a string value with name ''class'' indicating the element class to use. Optionally a list value with name ''properties'' can be used containing stub element properties to use for creating the element. Values in this list are string values where the name is the property key and the string value is the property value.
* Full name: ''composed.children''
* Type: list
* Default Value: empty list
* Example (*.deeclass)
====== Events ======
This behavior has no events.
====== 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). Saves if children elements have been already created.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorComposed.html,ECBehaviorComposed~@#.
Since DragonScript Module Version ''1.0''
====== Use Cases ======
* Add child elements to actor on creating it which the player can acquire, or break off.
* Create complex elements composed of different elements with little work.
====== Element Class Example ======
This example defines an element which contains a single child element which is a backpack.
class MyElement extends BehaviorElementClass
public var ECBehaviorComponent component
public var ECBehaviorCollider collider
public var ECBehaviorComposed composed
func new()
// add component which contains a rig with the bone 'backpack'
component = ECBehaviorComponent.new(this, null)
// add collider to have something to attach children to
collider = ECBehaviorCollider.new(this, component)
// add composed behavior and add a child definition to it
composed = ECBehaviorComposed.new(this)
var Dictionary child = Dictionary.new()
child.setAt("class", "MyBackpackClass")
var Dictionary properties = Dictionary.new()
properties.setAt("attachToParent.attachSlot", "backpack")
child.setAt("properties", properties)
composed.getChildren().add(child)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]