Reference › Function reference › Platform

Platform.unit_level.GetUnitLevelObservation

public

Call as

addon.Platform:GetUnitLevelObservation(unit)

Available directly through addon; no dependency is needed.

What it does

Observe a readable raw unit level on known clients. A readable absent unit returns exists=false; present units require a positive finite integer UnitLevel. Unknown boss levels, missing, failed, restricted or malformed observations return nil with a reason. This does not use effective or scaled levels.

Arguments

NameTypeWhat it does
selfRMPlatformRotation Master platform adapter (implicit with colon calls).
unitstringUnit token whose raw level should be observed.

Returns

1table | nilFresh readable record with exists and, when present, a positive integer level.
2string | nilAvailability or query-validation reason for a nil level observation.

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
UnitLevelClassic 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 target = addon.Platform:GetUnitLevelObservation("target")
local player = addon.Platform:GetUnitLevelObservation("player")
if not target or not player or not player.exists then return nil end
return target.exists and target.level < player.level

Dependencies

Source

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

Platform.unit_level.GetUnitLevelObservation(self, unit)
    if not self:CanReadValue(unit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if self:GetClientFamily()=='unknown' then return nil,'unsupported-client' 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
    if type(UnitLevel)~='function' then return nil,'missing-api' end
    local levelOk,level=pcall(UnitLevel,unit)
    if not levelOk then return nil,'api-error' end
    if not self:CanReadValue(level) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(level) then return nil,'restricted-value' end
    if level==nil then return nil,'level-data-unavailable' end
    if not finite(level) then return nil,'invalid-api-result' end
    if level<0 then return nil,'level-data-unavailable' end
    if level==0 or level%1~=0 then return nil,'invalid-api-result' end
    return {exists=true,level=level}

Back to Function reference