{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorRandomizeCreation**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorRandomizeCreation ======
Behavior adding support to randomize creation.
This behavior is typically used to add variation to game worlds by randomly creating or not creating element. This affects only elements added to a game world. Loading a game world does not trigger randomization.
This behavior uses #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorPreventCreation.html,BehaviorPreventCreation~@# to randomly prevent the element to be created and added to the game world. This check is done after #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorPrepareStub.html,BehaviorPrepareStub~@# supporting behaviors have potentially modified the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1StubElement.html,StubElement~@#.
====== Instance Counts ======
This behavior can be used only once on an element.
====== Element Class Properties ======
Element class properties have the prefix ''randomizeCreation.''.
===== probability =====
Set probability this element is created.
* Full name: ''randomizeCreation.probability''
* Type: float
* Default Value: 1
* Restriction: At least 0 and at most 1
* Example (*.deeclass) 0.5
====== 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 not required element class to be persistable (setPersistable).
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorRandomizeCreation.html,ECBehaviorRandomizeCreation~@#.
Since DragonScript Module Version ''1.23''
====== Use Cases ======
* Randomly create an element each time the element is added to a game world.
====== Element Class Example ======
This example defines an element which is randomly created.
class MyElement extends BehaviorElementClass
public var ECBehaviorRandomizeCreation randomizeCreation
func new()
randomizeCreation = ECBehaviorRandomizeCreation.new(this)
randomizeCreation.getProbability().setValue(0.5)
end
end
====== Behavior Factory ======
Using element class supporting adding behaviors the behavior can be added like this:
0.5
====== Live Examples ======
* [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]