呼叫方式
Conditions.spatial_stats.aggregate(values, operation)
記錄相依項目 Conditions.spatial_stats.aggregate,然後以該名稱呼叫。含命名空間的呼叫不會傳入 self:請使用冒號呼叫,或自行傳入該物件。
作用
Reduces the per-unit readings a PROXIMITY_* condition collected to one statistic: their average, minimum or maximum.
參數
| 名稱 | 類型 | 作用 |
|---|---|---|
values | number[] | Readings from the units in range. |
operation | string | average, minimum or maximum. |
傳回值
| 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. |
版本
內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。
它不會直接讀取任何遊戲 API。
插件如何呼叫它
- 範圍內的生命力 (evaluate)
local v,aggregateReason=aggregate(values,value.operation) - 範圍內的生命力百分比 (evaluate)
local v,aggregateReason=aggregate(values,value.operation) - 範圍內的法力 (evaluate)
local v,aggregateReason=aggregate(values,value.operation) - 範圍內的法力百分比 (evaluate)
local v,aggregateReason=aggregate(values,value.operation)
原始碼
Conditions/spatial_stats.lua,第 107 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。
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"