RandomSequenceBehavior

RandomSequenceBehavior

Runs its child behaviors one at a time, in random order. If any child behavior fails, the entire sequence fails. If they all succeed, the entire sequence succeeds.

Extends

Members

# behaviors :Array.<Behavior>

The child behaviors.

Warning: cannot be set using set(). Must be hard-coded into your derived class.

Type:
Inherited From:
Example:
class MyCompositeBehavior extends CompositeBehavior {
 get behaviors() { return [ChildBehaviorA, ChildBehaviorB]; }
}

# actor :Actor

The actor that is running the behavior.

Type:
  • Actor
Inherited From:

# parent :Behavior

The parent behavior in the behavior tree.

Type:
Inherited From:

# tickRate :number

The tick rate in milliseconds. If a behavior doesn't return an immediate result, it will run periodically at the frequency of the tick rate. If the tick rate is set to 0, the behavior won't tick and won't run do().

Type:
  • number
Inherited From:
Default Value:
  • 100

Methods

# startChild(behavior, optionsopt)

Starts a child behavior.

Parameters:
Name Type Attributes Description
behavior Behavior

The class name of the child behavior.

options Object <optional>

An optional options object to be passed to the child's init().

# reportSuccess(child, dataopt)

Called by a child from succeed().

Parameters:
Name Type Attributes Description
child Behavior

The child that is reporting.

data Object <optional>

Optional data from child.

# reportFailure(child, dataopt)

Called by a child from fail().

Parameters:
Name Type Attributes Description
child Behavior

The child that is reporting.

data Object <optional>

Optional data from child.

# init(optionsopt)

Called when the behavior is instantiated.

Parameters:
Name Type Attributes Description
options Object <optional>

Optional option object passed to set()

Inherited From:

# set(options)

Sets one or more internal properties of the behavior. The internal name of each property will be the name of the option prefaced by "_". You should define corresponding getters to access these internal properties.

    class MyBehavior extends Behavior {
        get growth() {return this._growth || 0.5};
    }

    const behavior = MyBehavior.create();
    behavior.set({growth: 2});
Parameters:
Name Type Description
options Object
Inherited From:

# do(delta)

This is where the work of the behavior actually happens. If you create your own behavior overload do. This will be called once per tick`.

Note: do will be called for for the first time at random interval less than the tick rate. (This is to prevent actors that spawn simultaneously from all processing their behaviors at the save time.) If you want something to happen instantly, put it in init instead of do.

Parameters:
Name Type Description
delta number

Time in milliseconds since the last invocation of do.

Inherited From:

# destroy()

Ends the behavior. Usually you want to report succeed or fail instead.

Inherited From:

# succeed(dataopt)

Ends the behavior and reports that it has succeeded to its parent.

Parameters:
Name Type Attributes Description
data Object <optional>

An optional data object that will be passed to the parent behavior.

Inherited From:

# fail(dataopt)

Ends the behavior and reports that it has failed to its parent.

Parameters:
Name Type Attributes Description
data Object <optional>

An optional data object that will be passed to the parent behavior.

Inherited From: