Class BehaviourTree

Representation of behaviour trees (or forests) with separated important and additional data.

The main advantage of this structure is that all properties of Nodes are stored directly, while additional data needed for other purposes, eg. editing in BtCreator, are stored in a separate table. However, for a user, it is possible to store any properties on the nodes themselves and they get assigned to the appropriate table.

Functions

BehaviourTree:New () Creates a new instance of BehaviourTree
BehaviourTree.list (project) Lists all available BehaviourTrees.
BehaviourTree.load (name) Loads a previously saved tree.
BehaviourTree.save (bt, name) Saves the tree under the specified name.

Tables

BehaviourTree Stored fields.

Methods

BehaviourTree:Combine (other, f) Add all nodes from the other tree to the current one.
BehaviourTree:NewNode (params) Creates a new Node that belongs to the tree.
BehaviourTree:Save (name) Alias to BehaviourTree.save
BehaviourTree:SetRoot (root) Roots the behaviour tree on the specified, already created node.
BehaviourTree:Visit (f[, after]) Invokes the given function on all nodes of the tree depth-first.

Class Node

Node Directly stored fields.
Node:ChangeID (newId) Changes the ID of the node.
Node:Connect (toNode) Connect the node to another, making it its child
Node:Disconnect (fromNode) Disconnects the node from its child.
Node:Relocate (newTree) Informs the node that it is relocated to a new tree.
Node:Remove () Removes the node from its tree.


Functions

BehaviourTree.list (project)
Lists all available BehaviourTrees.

Parameters:

  • project

Returns:

    {string} Array of behaviour tree names
BehaviourTree.load (name)
Loads a previously saved tree.

Parameters:

  • name name under which to look for the tree

Returns:

    BehaviourTree loaded tree if found, nil otherwise
BehaviourTree.save (bt, name)
Saves the tree under the specified name.

Parameters:

  • bt the tree which to save
  • name name under which to save, must not contain path-illegal characters

Returns:

    true if successful, nil otherwise
BehaviourTree:New ()
Creates a new instance of BehaviourTree

Returns:

    BehaviourTree

Tables

BehaviourTree
Stored fields.

Fields:

  • root Node main tree or nil
  • additionalNodes {Node,...} list of subtrees that are not connected to the root
  • properties {[string]=tab} additional data of nodes, accessed through their Node.id

Methods

BehaviourTree:Combine (other, f)
Add all nodes from the other tree to the current one.

Parameters:

  • other BehaviourTree The other tree.
  • f func Optional, function that is to be applied to each node of the other tree before it is combined, e.g. ID changes, return value is ignored.

Returns:

    Node The original root of the other tree.
BehaviourTree:NewNode (params)
Creates a new Node that belongs to the tree.

Remarks:

    The children field of the params is a list of already created nodes (and not only their own params).

Parameters:

  • params parameters of the node, such as id, nodeType, parameters and children

Returns:

    Node the created node
BehaviourTree:Save (name)
Alias to BehaviourTree.save

Parameters:

BehaviourTree:SetRoot (root)
Roots the behaviour tree on the specified, already created node.

Parameters:

  • root Node Node that becomes the new root.
BehaviourTree:Visit (f[, after])
Invokes the given function on all nodes of the tree depth-first. The traversing of the tree is terminated early if the function returns something.

Parameters:

  • f func The function that is to be invoked for every node.
  • after func Function that should be invoked when traversing out from the tree. (optional)

Returns:

    Whatever the function f returned along the way, or nil

Class Node

Represents a single node of BehaviourTree
Node
Directly stored fields.

Whenever any other name is accessed (get or set), it is routed to the properties field of BehaviourTree under the id of the current node.

Fields:

  • id string ID of the node
  • nodeType string specifies the type of the Node.
  • parameters {Parameter,...} list of parameters containing their names and values.
  • children {Node,...} list of current children of the node
Node:ChangeID (newId)
Changes the ID of the node. This has to be used over simply changing the value of the id slot in order to properly transfer the additional properties of the node.

Parameters:

  • newId
Node:Connect (toNode)
Connect the node to another, making it its child

Parameters:

  • toNode node to which to connect
Node:Disconnect (fromNode)
Disconnects the node from its child.

Parameters:

  • fromNode the child node from which to disconnect
Node:Relocate (newTree)
Informs the node that it is relocated to a new tree. It only affects the internal link to the tree and the properties table, the additionalNodes and root are not affected and have to be handled by the caller.

Parameters:

  • newTree the new BehaviourTree the node now belongs to
Node:Remove ()
Removes the node from its tree. Any nodes below this node get added to the additionalNodes list.
generated by LDoc 1.4.3 Last updated 2017-06-01 23:07:48