Game Development Reference
In-Depth Information
The behavior tree update loop
The main behavior tree update loop is responsible for both picking the current action that
should be executing as well as initializing, updating, and terminating any running action:
BehaviorTree.lua :
function BehaviorTree.Update(self, deltaTimeInMillis)
if (self.currentNode_ == nil) then
-- Find the first valid Action to execute.
self.currentNode_ = _EvaluateNode(
self, self.node_, deltaTimeInMillis);
end
if (self.currentNode_ ~= nil) then
local status = self.currentNode_.action_.status_;
if (status == Action.Status.UNINITIALIZED) then
self.currentNode_.action_:Initialize();
elseif (status == Action.Status.TERMINATED) then
self.currentNode_.action_:CleanUp();
-- Continue evaluation in case the Action's
parent was
-- a sequence. _ContinueEvaluation can return
nil, in
-- case the tree needs to be reevaluated.
self.currentNode_ = _ContinueEvaluation(
self, self.currentNode_, deltaTimeInMillis);
elseif (status == Action.Status.RUNNING) then
self.currentNode_.action_:Update(deltaTimeInMillis);
end
end
end
Search WWH ::




Custom Search