WoW Lua错误; 尝试调用全局变量 (a nil value)

我是Lua的新手,正在遵循_https://wowwiki.fandom.com/wiki/AddOn_tutorial_ 上的教程,但我无法使它正常工作; 我已经复制了代码,但我在**SetMapToCurrentZone ()**和 GetPlayerMapPosition("player") 函数中都收到了错误消息 "尝试调用全局'函数名' (a nil value)"。

这是整个Lua文件;

local zone = nil
local TimeSinceLastUpdate = 0
local function UpdateCoordinates(self, elapsed)
  if zone ~= GetRealZoneText() then
    zone = GetRealZoneText()
    SetMapToCurrentZone()
  end
  TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed
  if TimeSinceLastUpdate > .5 then
    TimeSinceLastUpdate = 0
    local posX, posY = GetPlayerMapPosition("player");
    local x = math.floor(posX * 10000)/100
    local y = math.floor(posY*10000)/100
    eCoordinatesFontString:SetText("|c98FB98ff("..x..", "..y..")")
  end
end

function eCoordinates_OnLoad(self, event,...)
  self:RegisterEvent("ADDON_LOADED")
end
function eCoordinates_OnEvent(self, event, ...)
  if event == "ADDON_LOADED" and ... == "eCoordinates" then
    self:UnregisterEvent("ADDON_LOADED")
    eCoordinates:SetSize(100, 50)
    eCoordinates:SetPoint("TOP", "Minimap", "BOTTOM", 5, -5)
    eCoordinates:SetScript("OnUpdate", UpdateCoordinates)
    local coordsFont = eCoordinates:CreateFontString("eCoordinatesFontString", "ARTWORK", "GameFontNormal")
    coordsFont:SetPoint("CENTER", "eCoordinates", "CENTER", 0, 0)
    coordsFont:Show()
    eCoordinates:Show()
  end
end

我该如何解决它?

点赞
用户2523387
用户2523387

这些函数在8.0中已被重命名并移动到包装对象C_Map.GetBestMapForUnit(需要“玩家”作为参数以产生相同的结果)和C_Map.GetPlayerMapPosition。您可以预期后续调用的功能将抛出相同的错误,只是这些行以前无法访问。当我再次在桌面上时,我可以检查整个代码示例,但您可以在Wowpedia上查找这些函数,特别是其他地图相关函数。

我建议使用Wowpedia而不是Wowwiki,这是个人偏好/印象,前者似乎接收到更多的常规更新。 (经过10年的分裂,两者似乎现在又正在合并)

2020-08-30 09:00:01