Reference › Function reference › Core

Core.level_conditions.GetConditionUnitLevel

public

Call as

addon:GetConditionUnitLevel(unit, cache)

Available directly through addon; no dependency is needed.

What it does

Resolve a readable raw unit level for condition evaluation. Known absence returns false; unavailable observations return nil with a reason. Cache observations within the supplied evaluation pass. Only valid player levels are retained between passes until a skill, profile or level refresh.

Arguments

NameTypeWhat it does
selfRMAddonRotation Master addon instance (implicit with colon calls).
unitstringUnit token whose raw level should be resolved.
cachetable | nilShared evaluation cache; nil observes directly without a per-pass cache.

Returns

1number | boolean | nilPositive integer level, false for a known absent unit, or nil when unavailable.
2string | nilAvailability or query-validation reason for a nil level.

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.

It reads no game API directly.

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

  • Level (evaluate)
    local observed,reason=addon:GetConditionUnitLevel(value.unit,cache)
  • Level (evaluate)
    local level,reason=addon:GetConditionUnitLevel("player",cache)

Source

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

Core.level_conditions.GetConditionUnitLevel(self, unit, cache)
    if not self.Platform:CanReadValue(unit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if self.Platform:GetClientFamily()=='unknown' then return nil,'unsupported-client' end
    local longterm=self.longtermCache
    if unit=='player' and type(longterm)=='table' then
        local level=longterm.conditionPlayerLevel
        if not self.Platform:CanReadValue(level) then return nil,'restricted-value' end
        if level~=nil then
            if type(level)~='number' or level~=level or level<=0 or level==math.huge or level%1~=0 then return nil,'invalid-api-result' end
            return level
        end
    end
    local record,reason=addon.Functions.cache.getCached(cache,self.Platform.GetUnitLevelObservation,self.Platform,unit)
    if not record then return nil,reason end
    if not record.exists then return false end
    if unit=='player' and type(longterm)=='table' then longterm.conditionPlayerLevel=record.level end
    return record.level

Back to Function reference