Reference › Function reference › Platform

Platform.creature_type.GetUnitCreatureTypeID

public

Call as

addon.Platform:GetUnitCreatureTypeID(unit)

Available directly through addon; no dependency is needed.

What it does

Observe creature identity from native UnitCreatureType return two on probe- and restricted-policy clients. Check exact UnitExists(unit) first; readable false returns false without requiring or calling creature metadata. A present unit requires a readable finite numeric ID; the unused localized name does not affect availability. Preserve signed, fractional, zero and future finite IDs as known values. Missing, failed, nil, restricted or malformed required facts return nil with a reason. No creature enumeration, translated caption comparison or longterm cache is added.

Arguments

NameTypeWhat it does
selfRMPlatformRotation Master platform adapter (implicit with colon calls).
unitstringReadable nonempty selected unit token, passed unchanged as the single argument to existence and creature metadata queries.

Returns

1number | boolean | nilFinite native creature ID, false for known unit absence, or nil when required observations are unavailable.
2string | nilPolicy, query-validation or required-observation availability reason for a nil ID.

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
UnitCreatureTypeClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitExistsClassic 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 id = addon.Platform:GetUnitCreatureTypeID("target")
if id == nil then return nil end
-- false (no target) never equals 6, the Undead creature type.
return id == 6

Source

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

Platform.creature_type.GetUnitCreatureTypeID(self, unit)
    local policy=self:GetCombatDataPolicy()
    if policy~='probe' and policy~='restricted' then return nil,'unsupported-policy' end
    if not self:CanReadValue(unit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' 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 false end
    local native=UnitCreatureType
    if type(native)~='function' then return nil,'missing-api' end
    local observed,_,id=pcall(native,unit)
    if not observed then return nil,'api-error' end
    if not self:CanReadValue(id) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(id) then return nil,'restricted-value' end
    if id==nil then return nil,'unit-creature-type-unavailable' end
    if type(id)~='number' or id~=id or id==math.huge or id==-math.huge then return nil,'invalid-api-result' end
    return id

Back to Function reference