Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » 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 BehaviorPreventCreation to randomly prevent the element to be created and added to the game world. This check is done after BehaviorPrepareStub supporting behaviors have potentially modified the StubElement.
This behavior can be used only once on an element.
Element class properties have the prefix randomizeCreation.
.
Set probability this element is created.
randomizeCreation.probability
<float name='randomizeCreation.probability'>0.5</float>
This behavior has no events.
This behavior requires no other behaviors.
This behavior does not support optional behaviors.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.23
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
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='ECBehaviorRandomizeCreation'> <!-- set element properties. omit property prefix if used inside behavior tag --> <float name='.probability'>0.5</float> </behavior> </elementClass>