Call as
Conditions.spatial_stats.aggregate(values, operation)
Record the dependency Conditions.spatial_stats.aggregate, then call it by that name. A namespaced call does not pass self: use a colon call or pass the object yourself.
What it does
Reduces the per-unit readings a PROXIMITY_* condition collected to one statistic: their average, minimum or maximum.
Arguments
| Name | Type | What it does |
|---|---|---|
values | number[] | Readings from the units in range. |
operation | string | average, minimum or maximum. |
Returns
| 1 | number | nil | The statistic, or nil when it cannot be computed. |
|---|---|---|
| 2 | string | nil | Reason for nil: no-units-in-range, statistic-unavailable (a nonfinite sum) or invalid-operation. |
Editions
Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.
It reads no game API directly.
How the addon calls it
- Health Within Range (evaluate)
local v,aggregateReason=aggregate(values,value.operation) - Health Percentage Within Range (evaluate)
local v,aggregateReason=aggregate(values,value.operation) - Mana Within Range (evaluate)
local v,aggregateReason=aggregate(values,value.operation) - Mana Percentage Within Range (evaluate)
local v,aggregateReason=aggregate(values,value.operation)
Source
Conditions/spatial_stats.lua, line 107. Read only in game; Duplicate makes an editable copy.
Conditions.spatial_stats.aggregate(values, operation)
if #values==0 then return nil,"no-units-in-range" end
local value=values[1]
if operation=="average" then
local sum=0;for _,current in ipairs(values) do sum=sum+current end
if sum==math.huge or sum==-math.huge or sum~=sum then return nil,"statistic-unavailable" end
return sum/#values
elseif operation=="minimum" or operation=="maximum" then
for index=2,#values do
if operation=="minimum" then value=math.min(value,values[index])
else value=math.max(value,values[index]) end
end
return value
end
return nil,"invalid-operation"