參考資料 › 函式參考 › 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}

返回函式參考