參考資料 › 函式參考 › Platform

Platform.range.GetRangeCheckBounds

公用

呼叫方式

addon.Platform:GetRangeCheckBounds(unit)

可直接透過 addon 使用,不需要相依項目。

作用

讀取某個單位的公開 LibRangeCheck 距離區間。成功的上限是包含的;正的失敗下限是嚴格的。零下限是合成的。兩個邊界都不是精確距離,缺少上限也不能證明該單位在所有半徑之外。無法使用、格式錯誤、受限或失敗的觀測會傳回 nil 及原因。

參數

名稱類型作用
selfRMPlatformRotation Master 平台轉接器(使用冒號呼叫時隱含傳入)。
unitstring要觀測其與玩家距離的目前單位代碼。

傳回值

1table | nil可讀的區間,帶有選擇性的最小與最大邊界(碼)。至少存在一個邊界;無法使用時為 nil。
2string | nil結果為 nil 時的可用性或驗證原因。

版本

內建輔助函式在每個版本上都會註冊。不同的是它們讀取的遊戲 API;某個 API 不存在時,輔助函式會改用備用方式,或傳回 nil 並附上原因。

它不會直接讀取任何遊戲 API。

機密值(正式版與永久)

在正式版與永久上,遊戲交給插件的是機密值。此輔助函式會檢查它讀取的內容(addon.Platform:CanReadValue),遇到無法比較的機密值時,會傳回 nil 並附上原因(例如 restricted-value),而不是傳回該機密值。請將 nil 視為無法使用,而非假。

範例

local bounds = addon.Platform:GetRangeCheckBounds("target")
if not bounds then return nil end
if bounds.maximum and bounds.maximum <= 8 then return true end
if bounds.minimum and bounds.minimum >= 8 then return false end
return nil -- the interval straddles 8 yards

原始碼

Platform/range.lua,第 129 行。在遊戲中為唯讀;「複製」會產生一份可編輯的複本。

Platform.range.GetRangeCheckBounds(self, unit)
    if not self:CanReadValue(unit) then return nil,'restricted-value' end
    if type(unit)~='string' or unit=='' then return nil,'invalid-unit' end
    if not LibStub then return nil,'missing-range-provider' end
    local loaded,provider=pcall(function() return LibStub('LibRangeCheck-3.0',true) end)
    if not loaded or not provider or type(provider.GetRange)~='function' then return nil,'missing-range-provider' end
    local ok,minimum,maximum=pcall(provider.GetRange,provider,unit)
    if not ok then return nil,'range-provider-error' end
    if not self:CanReadValue(minimum) or not self:CanReadValue(maximum) then return nil,'restricted-value' end
    for _,bound in pairs({minimum=minimum,maximum=maximum}) do
        if type(bound)~='number' or bound~=bound or bound<0 or bound==math.huge then return nil,'invalid-range-result' end
    end
    if minimum==nil and maximum==nil then return nil,'range-unavailable' end
    if minimum and maximum and minimum>maximum then return nil,'invalid-range-result' end
    return {minimum=minimum,maximum=maximum}

返回函式參考