参考 › 函数参考 › Platform

Platform.range.GetNameplateMaxDistance

公共

调用方式

addon.Platform:GetNameplateMaxDistance()

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

作用

使用受支持的 CVar API 读取当前正的姓名板可见距离。这会限制“距离内计数”查询;它不能证明所有附近的单位都已被观测到。缺失、格式错误、受限或失败的观测会返回 nil 及原因。

参数

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

返回值

1number | nil当前的正可见距离,单位为码;不可用时为 nil。
2string | nil结果为 nil 时的可用性原因。

版本

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

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

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

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

插件如何调用它

  • 距离内计数 (widget)
    local maximum=addon.Platform:GetNameplateMaxDistance()

源码

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

Platform.range.GetNameplateMaxDistance(self)
    local query=C_CVar and C_CVar.GetCVar or GetCVar
    if type(query)~='function' then return nil,'missing-api' end
    local ok,value=pcall(query,'nameplateMaxDistance')
    if not ok then return nil,'api-error' end
    if not self:CanReadValue(value) then return nil,'restricted-value' end
    if type(value)~='string' and type(value)~='number' then return nil,'nameplate-distance-unavailable' end
    local maximum=tonumber(value)
    if not maximum or maximum~=maximum or maximum<=0 or maximum==math.huge then return nil,'nameplate-distance-unavailable' end
    return maximum

返回函数参考