Call as
Platform.mobinfo2.readField(self, object, key)
Record the dependency Platform.mobinfo2.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] in protected mode for MobInfo2 data. Returns the value (possibly nil), or nil with "restricted-value" when the object or the value is secret, "invalid-mobinfo2-data" when object is not a table, or "mobinfo2-data-error" when indexing raises an error.
Arguments
| Name | Type | What it does |
|---|---|---|
self | RMPlatform | Rotation Master platform adapter (normally addon.Platform), used for its CanReadValue check. |
object | table | Table to index; any other type is rejected. |
key | any | Field name to read. |
Returns
| 1 | any | The field value, possibly nil; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure; nil on success. |
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
Platform.mobinfo2.GetMobInfo2Observationlocal query,queryReason=readField(self,_G,'MI2_GetMobData')Platform.mobinfo2.hitCountlocal hits,reason=readField(self,resists,school..'Hits')
Source
Platform/mobinfo2.lua, line 29. Read only in game; Duplicate makes an editable copy.
Platform.mobinfo2.readField(self, object, key)
if not self:CanReadValue(object) then return nil,'restricted-value' end
if type(object)~='table' then return nil,'invalid-mobinfo2-data' end
local ok,value=pcall(function() return object[key] end)
if not ok then return nil,'mobinfo2-data-error' end
if not self:CanReadValue(value) then return nil,'restricted-value' end
return value