参考 › 函数参考 › Platform

Platform.instance.GetInstanceObservation

公共

调用方式

addon.Platform:GetInstanceObservation()

可直接通过 addon 使用,无需依赖项。

作用

观测一个受保护的无参数 IsInInstance 元组。所需的可读布尔成员值与类型字段无关:已知在副本外时直接返回,不解释未使用的类型;在副本内时返回可读的字符串类型,或在该次要字段不可用时返回 instanceTypeReason。检测是否在副本外的调用方只需要成员值;在副本内比较类型时必须检查次要原因。不会添加户外、区域或单位推断。

参数

名称类型作用
selfRMPlatformRotation Master 平台适配器(使用冒号调用时隐含传入)。

返回值

1table | nil记录包含 inInstance,在副本内时还包含 instanceType 或 instanceTypeReason;成员值不可用时为 nil。
2string | nil记录为 nil 时的客户端策略、原生调用或所需成员身份的可用性原因。

版本

内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。

  • 该版本不可用(原因见提示)
  • 仅在暴雪的弃用兼容层开启时
游戏 API经典旧世TBC 周年版经典进阶服永久服正式服
IsInInstance经典旧世TBC 周年版经典进阶服永久服正式服
canaccessvalue经典旧世TBC 周年版经典进阶服永久服正式服

秘密值(正式服和永久服)

在正式服和永久服上,游戏交给插件的是秘密值。此辅助函数会检查它读取的内容(addon.Platform:CanReadValue),遇到无法比较的秘密值时返回 nil 并附上原因(例如 restricted-value),而不是返回该秘密值。请将 nil 视为不可用,而不是假。

示例

local record = addon.Platform:GetInstanceObservation()
if not record then return nil end
if not record.inInstance then return false end
if not record.instanceType then return nil end
return record.instanceType == "raid"

源码

Platform/instance.lua,第 18 行。在游戏中为只读;“复制”会生成一份可编辑的副本。

Platform.instance.GetInstanceObservation(self)
    local family=self:GetClientFamily()
    if family~='retail' and family~='forever' and family~='era' and family~='tbc' and family~='progression' then return nil,'unsupported-policy' end
    if type(IsInInstance)~='function' then return nil,'missing-api' end
    local ok,inInstance,instanceType=pcall(IsInInstance)
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(inInstance) then return nil,'restricted-value' end
    if canaccessvalue and not canaccessvalue(inInstance) then return nil,'restricted-value' end
    if inInstance==nil then return nil,'instance-data-unavailable' end
    if type(inInstance)~='boolean' then return nil,'invalid-api-result' end
    if not inInstance then return {inInstance=false} end
    if not self:CanReadValue(instanceType) then return {inInstance=true,instanceTypeReason='restricted-value'} end
    if canaccessvalue and not canaccessvalue(instanceType) then return {inInstance=true,instanceTypeReason='restricted-value'} end
    if instanceType==nil then return {inInstance=true,instanceTypeReason='instance-type-unavailable'} end
    if type(instanceType)~='string' then return {inInstance=true,instanceTypeReason='invalid-api-result'} end
    return {inInstance=true,instanceType=instanceType}

返回函数参考