Game Development Reference
In-Depth Information
Handling agent communications
Typically, agent communications will rely heavily on team-only events as well as specific
callbacks based on the event type. First, we'll create internal event handling, which will
pass back our userData table to the handler as well as filter team-specific events. By
adding a teamOnly field to our event, we can filter messages that are only meant for the
sending agent's team.
As we also want to filter out events that our agents don't want to handle, we'll manage an
individual event callback per event type. This can be easily accomplished with an associat-
ive array indexed by our agent's ID:
AgentCommunications.lua :
local agentUserData = {};
local agentCallbacks = {};
local function AgentCommunications_HandleEvent(
sandbox, agent, eventType, event)
local callbacks = agentCallbacks[agent:GetId()];
if (callbacks == nil or
callbacks[eventType] == nil or
type(callbacks[eventType]) ~= "function") then
return;
end
if (not event["teamOnly"] or
(event["teamOnly"] and agent:GetTeam() ==
event["team"])) then
callbacks[eventType](
agentUserData[agent:GetId()], eventType, event);
end
end
Search WWH ::




Custom Search