Game Development Reference
In-Depth Information
Updating an action
Once an action has transitioned to a running state, it will receive callbacks to the update
function every time the agent itself is updated, until the action decides to terminate. To
avoid an infinite loop case, the update function must return a terminated status when a con-
dition is met; otherwise, our agents will never be able to finish the running action.
Note
An update function isn't a hard requirement for our actions, as actions terminate immedi-
ately by default if no callback function is present.
Action.lua :
function Action.Update(self, deltaTimeInMillis)
if (self.status_ == Action.Status.TERMINATED) then
-- Immediately return if the Action has already
-- terminated.
return Action.Status.TERMINATED;
elseif (self.status_ == Action.Status.RUNNING) then
if (self.updateFunction_) then
-- Run the update function if one is specified.
self.status_ = self.updateFunction_(
deltaTimeInMillis, self.userData_);
-- Ensure that a status was returned by the
update
-- function.
assert(self.status_);
else
-- If no update function is present move the
action
-- into a terminated state.
self.status_ = Action.Status.TERMINATED;
end
end
return self.status_;
end
Search WWH ::




Custom Search