Scripted Nodes <s:...>¶
This is the whole class of leaf nodes that are implemented as scripts. Prefix s: is followed by the name of the script that should be attached to control entity (not to the entity defining the behavior tree node).
I.e if you have entity Zombie and somewhere in its behavior tree you have entity <s:btZombieWalking>, you should attach script btZombieWalking to the Zombie entity and it would be used by the behavior tree so long as the script implements a certain interface.
Adapter scripts are basically a glue between behavior tree and the rest of DBB scripts and the game world. You should not make them too complicated and recommended is if they grow too much, to extract parts that are not directly related to the behavior tree into separate script with its own interface, that adapter script would use.
Adapter Script Node Interface¶
Not yet finalized
This is a very partial interface at the moment. It would most definitely change in the future.
Adapter script should implement the following interface:
export interface BehaviorTreeNodeAdapter {
onCheck(): CheckFunction;
}
type CheckFunction = (event: any, node: TreeNode, tree: Script) => NodeStatus
interface TreeFeed {
process(node: TreeNode, event: any): NodeStatus
}
interface Blackboard {
setEntity(key: string, value: Entity): void
getEntity(key: string): Entity | undefined
setString(key: string, value: string): void
getString(key: string): string | undefined
}
interface Tree {
getFeed(): TreeFeed
isDebugOn(): boolean
getBlackboard(): Blackboard
}
type NodeAttributes = Record<string, string>
type TreeNode = {
getName(): string
getAttributes(): NodeAttributes
getChildren(): TreeNode[]
}
const NodeStatuses = [ 'running', 'success', 'failure'] as const;
type NodeStatus = typeof NodeStatuses[number];
Notice here several things:
- there are three possible statuses of the node: 'success', 'failure' and 'running', which are simply strings
- onCheck method should return a function of type CheckFunction that would be called by the behavior tree to check the status of the node
- this CheckFunction function should return the status of the node
Adapter Script Node Example¶
class Script {
// ...
// some methods and properties
// particularly isWalking() and closeToTarget() methods
// ...
onCheck() {
return () => {
if (this.isWalking()) {
return 'running';
} else if (this.closeToTarget()) {
return 'success';
} else {
return 'failure';
}
}
}
}
Note: the interface is probably not complete at the time. I feel like waiting till DBB publishes the script export/import feature, so I could simply export the interface before it could be made final.