Blackboard
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.
Item Index
Methods
_getMemory
-
treeScope -
nodeScope
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:
-
treeScopeStringThe id of the tree scope.
-
nodeScopeStringThe id of the node scope.
Returns:
A memory object.
_getNodeMemory
-
treeMemory -
nodeScope
Internal method to retrieve the node context memory, given the tree memory. If the memory does not exist, this method creates is.
Parameters:
-
treeMemoryStringthe tree memory.
-
nodeScopeStringThe id of the node in scope.
Returns:
The node memory.
_getTreeMemory
-
treeScope
Internal method to retrieve the tree context memory. If the memory does not exist, this method creates it.
Parameters:
-
treeScopeStringThe id of the tree in scope.
Returns:
The tree memory.
get
-
key -
treeScope -
nodeScope
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:
-
keyStringThe key to be retrieved.
-
treeScopeStringThe tree id if accessing the tree or node memory.
-
nodeScopeStringThe node id if accessing the node memory.
Returns:
The value stored or undefined.
initialize
()
Initialization method.
set
-
key -
value -
treeScope -
nodeScope
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:
-
keyStringThe key to be stored.
-
valueStringThe value to be stored.
-
treeScopeStringThe tree id if accessing the tree or node memory.
-
nodeScopeStringThe node id if accessing the node memory.
