API Documentation for: 0.1.0
Show:

Blackboard Class

Defined in: Blackboard:35
Module: Behavior3JS

The Blackboard is the memory structure required by BehaviorTree and its nodes. It only have 2 public methods: set and get. These methods works in 3 different contexts: global, per tree, and per node per tree.

Suppose you have two different trees controlling a single object with a single blackboard, then:

  • In the global context, all nodes will access the stored information.
  • In per tree context, only nodes sharing the same tree share the stored information.
  • In per node per tree context, the information stored in the blackboard can only be accessed by the same node that wrote the data.

The context is selected indirectly by the parameters provided to these methods, for example:

// getting/setting variable in global context
blackboard.set('testKey', 'value');
var value = blackboard.get('testKey');

// getting/setting variable in per tree context
blackboard.set('testKey', 'value', tree.id);
var value = blackboard.get('testKey', tree.id);

// getting/setting variable in per node per tree context
blackboard.set('testKey', 'value', tree.id, node.id);
var value = blackboard.get('testKey', tree.id, node.id);

Note: Internally, the blackboard store these memories in different objects, being the global on _baseMemory, the per tree on _treeMemory and the per node per tree dynamically create inside the per tree memory (it is accessed via _treeMemory[id].nodeMemory). Avoid to use these variables manually, use get and set instead.

Methods

_getMemory

(
  • treeScope
  • nodeScope
)
Object protected

Defined in _getMemory:127

Internal method to retrieve the context memory. If treeScope and nodeScope are provided, this method returns the per node per tree memory. If only the treeScope is provided, it returns the per tree memory. If no parameter is provided, it returns the global memory. Notice that, if only nodeScope is provided, this method will still return the global memory.

Parameters:

  • treeScope String

    The id of the tree scope.

  • nodeScope String

    The id of the node scope.

Returns:

Object:

A memory object.

_getNodeMemory

(
  • treeMemory
  • nodeScope
)
Object protected

Defined in _getNodeMemory:108

Internal method to retrieve the node context memory, given the tree memory. If the memory does not exist, this method creates is.

Parameters:

  • treeMemory String

    the tree memory.

  • nodeScope String

    The id of the node in scope.

Returns:

Object:

The node memory.

_getTreeMemory

(
  • treeScope
)
Object protected

Defined in _getTreeMemory:87

Internal method to retrieve the tree context memory. If the memory does not exist, this method creates it.

Parameters:

  • treeScope String

    The id of the tree in scope.

Returns:

Object:

The tree memory.

get

(
  • key
  • treeScope
  • nodeScope
)
Object

Defined in get:176

Retrieves a value in the blackboard. If treeScope and nodeScope are provided, this method will retrieve the value from the per node per tree memory. If only the treeScope is provided, it will retrieve the value from the per tree memory. If no parameter is provided, this method will retrieve from the global memory. If only nodeScope is provided (but treeScope not), this method will still try to retrieve from the global memory.

Parameters:

  • key String

    The key to be retrieved.

  • treeScope String

    The tree id if accessing the tree or node memory.

  • nodeScope String

    The node id if accessing the node memory.

Returns:

Object:

The value stored or undefined.

initialize

()

Defined in initialize:76

Initialization method.

set

(
  • key
  • value
  • treeScope
  • nodeScope
)

Defined in set:155

Stores a value in the blackboard. If treeScope and nodeScope are provided, this method will save the value into the per node per tree memory. If only the treeScope is provided, it will save the value into the per tree memory. If no parameter is provided, this method will save the value into the global memory. Notice that, if only nodeScope is provided (but treeScope not), this method will still save the value into the global memory.

Parameters:

  • key String

    The key to be stored.

  • value String

    The value to be stored.

  • treeScope String

    The tree id if accessing the tree or node memory.

  • nodeScope String

    The node id if accessing the node memory.