Game Development Reference
In-Depth Information
Sequence evaluation
A sequence is nearly the opposite of a selector where the first failure will result in the se-
quence returning a failure. As sequences can execute multiple actions sequentially, we can
take in an index number that represents the current child from which we should start our
evaluation. This allows the behavior tree to continue the evaluation from where it left off:
BehaviorTree.lua :
_EvaluateSequence = function(self, node, deltaTimeInMillis,
index)
-- Try and evaluate all children. Returns a false
result if a
-- child is unable to execute, such as a condition
failing or
-- child sequence/selector being unable to find a valid
Action
-- to run.
index = index or 1;
for count=index, #node.children_ do
local child = node:GetChild(count);
if (child.type_ == BehaviorTreeNode.Type.ACTION) then
-- Execute all Actions, since Actions cannot
fail.
return { node = child, result = true};
elseif (child.type_ ==
BehaviorTreeNode.Type.CONDITION) then
local result = child.evaluator_(self.userData_);
-- Break out of execution if a condition fails.
if (not child.evaluator_(self.userData_)) then
return { result = false };
end
elseif (child.type_ ==
BehaviorTreeNode.Type.SELECTOR) then
Search WWH ::




Custom Search