Reference › Function reference › Platform

Platform.unit_stat.GetUnitStatObservation

public

Call as

addon.Platform:GetUnitStatObservation(unit, stat)

Available directly through addon; no dependency is needed.

What it does

Observe the effective statistic from native return two only. On probe- and restricted-policy clients, query exact UnitExists(unit), then UnitStat(unit,stat) for selector 1..5 or UnitArmor(unit) for selector 6. Known absence returns exists=false; missing, failed, restricted or nonfinite required facts return nil. Preserve finite signed, fractional and zero values; ignore all unused tuple fields. The 1..6 route is an RM selector policy, not a native value-domain limit.

Arguments

NameTypeWhat it does
selfRMPlatformRotation Master platform adapter (implicit with colon calls).
unitstringSelected nonempty unit token, unchanged in native calls.
statnumberIntegral RM statistic selector 1..5, or 6 for effective armor.

Returns

1table | nilRecord with exists=false, or exists=true and finite value; nil when unavailable.
2string | nilQuery, policy or observation availability reason.

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
UnitArmorClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitExistsClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitStatClassic EraTBC AnniversaryClassic progressionForeverRetail
canaccessvalueClassic 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.

Example

local armor = addon.Platform:GetUnitStatObservation("player", 6)
if not armor or not armor.exists then return nil end
return armor.value >= 10000

Dependencies

Source

Platform/unit_stat.lua, line 27. Read only in game; Duplicate makes an editable copy.

Platform.unit_stat.GetUnitStatObservation(self, unit, stat)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not self:CanReadValue(unit) or not self:CanReadValue(stat) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if not finite(stat) or stat%1~=0 or stat<1 or stat>6 then return nil,'invalid-stat-query' end
    if type(UnitExists)~='function' then return nil,'missing-api' end
    local existsOk,exists=pcall(UnitExists,unit)
    if not existsOk then return nil,'api-error' end
    if not self:CanReadValue(exists) then return nil,'restricted-value' end
    if exists==nil then return nil,'unit-data-unavailable' end
    if type(exists)~='boolean' then return nil,'invalid-api-result' end
    if not exists then return {exists=false} end
    local fn
    if stat==6 then fn=UnitArmor else fn=UnitStat end
    if type(fn)~='function' then return nil,'missing-api' end
    local ok,_,effective
    if stat==6 then ok,_,effective=pcall(fn,unit)
    else ok,_,effective=pcall(fn,unit,stat) end
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(effective) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(effective) then return nil,'restricted-value' end
    if effective==nil then return nil,'stat-data-unavailable' end
    if not finite(effective) then return nil,'invalid-api-result' end
    return {exists=true,value=effective}

Back to Function reference