Reference › Function reference › Core

Core.threat_count_conditions.readField

dependency

Call as

Core.threat_count_conditions.readField(platform, object, key)

Record the dependency Core.threat_count_conditions.readField, then call it by that name. A namespaced call does not pass self: use a colon call or pass the object yourself.

What it does

Reads object[key] for the threat-count conditions without letting a restricted value, a non-table object or an index error escape.

Arguments

NameTypeWhat it does
platformRMPlatformPlatform whose CanReadValue decides readability.
objectanyTable to read, such as the addon or a unit snapshot entry.
keyanyKey to read, such as "unitsInRange".

Returns

1anyThe field's value (possibly nil), or nil on failure.
2string | nilReason on failure: restricted-value, invalid-unit-snapshot or unit-snapshot-read-error.

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

Source

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

Core.threat_count_conditions.readField(platform, object, key)
    if not platform:CanReadValue(object) then return nil,'restricted-value' end
    if type(object)~='table' then return nil,'invalid-unit-snapshot' end
    local ok,value=pcall(function() return object[key] end)
    if not ok then return nil,'unit-snapshot-read-error' end
    if not platform:CanReadValue(value) then return nil,'restricted-value' end
    return value

Back to Function reference