Game Development Reference
In-Depth Information
Helper functions
Adding some object-oriented helper functions to handle child management as well as a
backward link to the nodes parent will allow the behavior tree to evaluate the nodes more
efficiently:
BehaviorTreeNode.lua :
function BehaviorTreeNode.AddChild(self, child, index)
index = index or (#self.children_ + 1);
table.insert(self.children_, index, child);
child.parent_ = self;
end
function BehaviorTreeNode.ChildIndex(self, child)
for index=1, #self.children_ do
if (self.children_[index] == child) then
return index;
end
end
return -1;
end
function BehaviorTreeNode.GetChild(self, childIndex)
return self.children_[childIndex];
end
function BehaviorTreeNode.GetNumberOfChildren(self)
return #self.children_;
end
function BehaviorTreeNode.GetParent(self)
return self.parent_;
end
Search WWH ::




Custom Search