API Documentation for: 0.1.0
Show:

Decorator Class

Extends BaseNode
Defined in: Decorator:35
Module: Behavior3JS

Decorator is the base class for all decorator nodes. Thus, if you want to create new custom decorator nodes, you need to inherit from this class.

When creating decorator nodes, you will need to propagate the tick signal to the child node manually, just like the composite nodes. To do that, override the tick method and call the _execute method on the child node. For instance, take a look at how the Inverter node inherit this class and how it call its children:

// Inherit from Decorator, using the util function Class.
var Inverter = b3.Class(b3.Decorator);
var p = Inverter.prototype;

    // Remember to set the name of the node. 
    p.name = 'Inverter';

    // Override the tick function
    p.tick = function(tick) {
        if (!this.child) {
            return b3.ERROR;
        }

        // Propagate the tick
        var status = this.child._execute(tick);

        if (status == b3.SUCCESS)
            status = b3.FAILURE;
        else if (status == b3.FAILURE)
            status = b3.SUCCESS;

        return status;
    };

Methods

_close

(
  • tick
)
protected

Inherited from BaseNode: _close:215

Wrapper for close method.

Parameters:

  • tick Tick

    A tick instance.

_enter

(
  • tick
)
protected

Inherited from BaseNode: _enter:177

Wrapper for enter method.

Parameters:

  • tick Tick

    A tick instance.

_execute

(
  • tick
)
Constant protected

Inherited from BaseNode: _execute:142

This is the main method to propagate the tick signal to this node. This method calls all callbacks: enter, open, tick, close, and exit. It only opens a node if it is not already open. In the same way, this method only close a node if the node returned a status different of b3.RUNNING.

Parameters:

  • tick Tick

    A tick instance.

Returns:

Constant:

The tick state.

_exit

(
  • tick
)
protected

Inherited from BaseNode: _exit:228

Wrapper for exit method.

Parameters:

  • tick Tick

    A tick instance.

_open

(
  • tick
)
protected

Inherited from BaseNode: _open:189

Wrapper for open method.

Parameters:

  • tick Tick

    A tick instance.

_tick

(
  • tick
)
Constant protected

Inherited from BaseNode: _tick:202

Wrapper for tick method.

Parameters:

  • tick Tick

    A tick instance.

Returns:

Constant:

A state constant.

close

(
  • tick
)

Inherited from BaseNode: close:270

Close method, override this to use. This method is called after the tick callback, and only if the tick return a state different from b3.RUNNING.

Parameters:

  • tick Tick

    A tick instance.

enter

(
  • tick
)

Inherited from BaseNode: enter:240

Enter method, override this to use. It is called every time a node is asked to execute, before the tick itself.

Parameters:

  • tick Tick

    A tick instance.

exit

(
  • tick
)

Inherited from BaseNode: exit:280

Exit method, override this to use. Called every time in the end of the execution.

Parameters:

  • tick Tick

    A tick instance.

initialize

()

Inherited from BaseNode but overwritten in initialize:87

Initialization method.

open

(
  • tick
)

Inherited from BaseNode: open:249

Open method, override this to use. It is called only before the tick callback and only if the not isn't closed.

Note: a node will be closed if it returned b3.RUNNING in the tick.

Parameters:

  • tick Tick

    A tick instance.

tick

(
  • tick
)

Inherited from BaseNode: tick:260

Tick method, override this to use. This method must contain the real execution of node (perform a task, call children, etc.). It is called every time a node is asked to execute.

Parameters:

  • tick Tick

    A tick instance.

Properties

category

String

Inherited from BaseNode but overwritten in category:77

Node category. Default to b3.DECORATOR.

description

String

Inherited from BaseNode: description:97

Node description.

id

String

Inherited from BaseNode: id:58

Node ID.

name

String

Inherited from BaseNode: name:66

Node name. Must be a unique identifier, preferable the same name of the class. You have to set the node name in the prototype.

parameters

Object

Inherited from BaseNode: parameters:107

A dictionary (key, value) describing the node parameters. Useful for defining parameter values in the visual editor. Note: this is only useful for nodes when loading trees from JSON files.

properties

Object

Inherited from BaseNode: properties:118

A dictionary (key, value) describing the node properties. Useful for defining custom variables inside the visual editor.

title

String

Inherited from BaseNode: title:87

Node title.