Reference › Function reference › Platform

Platform.unit_states.GetUnitStateObservation

public

Call as

addon.Platform:GetUnitStateObservation(unit, kind)

Available directly through addon; no dependency is needed.

What it does

Observe death or ghost state, or friendliness to the player, for the exact selected unit on probe- and restricted-policy clients. A missing, failed, restricted or malformed required observation is unavailable. Unit absence is unavailable rather than a negative match, including under NOT. No cross-poll state is retained.

Arguments

NameTypeWhat it does
selfRMPlatformRotation Master platform adapter (implicit with colon calls).
unitstringExact nonempty unit token to observe.
kindstringExactly dead for UnitIsDeadOrGhost, or friendly for UnitIsFriend(player, unit).

Returns

1boolean | nilReadable current state, or nil when unavailable.
2string | nilAvailability or query-validation reason when no current state can be read.

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
UnitExistsClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitIsDeadOrGhostClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitIsFriendClassic 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 friendly = addon.Platform:GetUnitStateObservation("target", "friendly")
local dead = addon.Platform:GetUnitStateObservation("target", "dead")
if friendly == nil or dead == nil then return nil end
return friendly and dead -- a friend to resurrect

Source

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

Platform.unit_states.GetUnitStateObservation(self, unit, kind)
    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(kind) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if kind~='dead' and kind~='friendly' then return nil,'invalid-unit-state-query' end
    local existsAPI=UnitExists
    if type(existsAPI)~='function' then return nil,'missing-api' end
    local existsOK,exists=pcall(existsAPI,unit)
    if not existsOK then return nil,'api-error' end
    if not self:CanReadValue(exists) then return nil,'restricted-value' end
    if exists==nil or exists==false then return nil,'unit-data-unavailable' end
    if type(exists)~='boolean' then return nil,'invalid-api-result' end
    local api
    if kind=='dead' then api=UnitIsDeadOrGhost else api=UnitIsFriend end
    if type(api)~='function' then return nil,'missing-api' end
    local ok,result
    if kind=='friendly' then ok,result=pcall(api,'player',unit)
    else ok,result=pcall(api,unit) end
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(result) then return nil,'restricted-value' end
    if result==nil then return nil,'unit-state-unavailable' end
    if type(result)~='boolean' then return nil,'invalid-api-result' end
    return result

Back to Function reference