Game Development Reference
In-Depth Information
Intermittent agent sightings
Now that we can handle sending out agent sighting events, we need a way to keep track of
the agents we currently know about. We can use the agent's blackboard as a place to store
all the visible agents the agent has ever seen and use that information to determine whether
new events should be sent out:
AgentSenses.lua :
local function UpdateVisibility(userData)
local agents = Sandbox.GetAgents(
userData.agent:GetSandbox());
local visibleAgents = {};
for index = 1, #agents do
if (agents[index] ~= userData.agent) then
canSeeAgentInfo = AgentSenses_CanSeeAgent(
userData, agents[index], true);
if (canSeeAgentInfo) then
visibleAgents[agents[index]:GetId()] =
canSeeAgentInfo;
end
end
end
local knownAgents =
userData.blackboard:Get("visibleAgents") or {};
HandleNewAgentSightings(
userData, knownAgents, visibleAgents);
for key, value in pairs(visibleAgents) do
knownAgents[key] = value;
end
userData.blackboard:Set("visibleAgents", knownAgents);
end
Search WWH ::




Custom Search