Reference › Function reference › Conditions

Conditions.spatial_stats.observation

dependency

Call as

Conditions.spatial_stats.observation(cache, method, unit, power)

Record the dependency Conditions.spatial_stats.observation, 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

Reads one health or mana number for a PROXIMITY_* condition through the evaluation cache, protected against errors. With power set it passes Enum.PowerType.Mana as the second argument; restricted, negative, NaN or infinite readings are rejected.

Arguments

NameTypeWhat it does
cachetable | nilEvaluation-pass cache passed to getCached, or nil to read directly.
methodfunctionAPI to call, such as UnitHealth or UnitPowerMax.
unitstringUnit token to read.
powerboolean | nilTruthy to read mana.

Returns

1number | nilThe reading, or nil when unavailable.
2string | nilReason for nil: missing-api, api-error, restricted-value or statistic-unavailable.

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.

  • Not available on that edition (the reason is in the tooltip)
  • Only while Blizzard's deprecation fallbacks are on
Game APIClassic EraTBC AnniversaryClassic progressionForeverRetail
Enum.PowerTypeClassic EraTBC AnniversaryClassic progressionForeverRetail

Secret values (Retail and Forever)

On Retail and Forever the game hands addons secret values. This helper checks what it reads (addon.Platform:CanReadValue) and returns nil with a reason such as restricted-value instead of a secret it cannot compare. Treat nil as unavailable, not as false.

How the addon calls it

Source

Conditions/spatial_stats.lua, line 60. Read only in game; Duplicate makes an editable copy.

Conditions.spatial_stats.observation(cache, method, unit, power)
    if type(method)~="function" then return nil,"missing-api" end
    local ok,current
    if power then ok,current=pcall(addon.getCached,cache,method,unit,Enum.PowerType.Mana)
    else ok,current=pcall(addon.getCached,cache,method,unit) end
    if not ok then return nil,"api-error" end
    if not addon.Platform:CanReadValue(current) then return nil,"restricted-value" end
    if type(current)~="number" or current~=current or current<0 or current==math.huge then return nil,"statistic-unavailable" end
    return current

Back to Function reference