Reference › Function reference › Conditions

Conditions.spatial_stats.aggregate

dependency

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

NameTypeWhat it does
valuesnumber[]Readings from the units in range.
operationstringaverage, minimum or maximum.

Returns

1number | nilThe statistic, or nil when it cannot be computed.
2string | nilReason 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

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"

Back to Function reference