User Tools

Site Tools


dragengine:modules:dragonscript:behavior_randomizecreation

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.

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)
    <float name='randomizeCreation.probability'>0.5</float>

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

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:

<?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>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_randomizecreation.txt · Last modified: 2025/03/11 19:56 by dragonlord