簡體   English   中英

WoW Lua 錯誤; 嘗試調用全局(零值)

[英]WoW Lua error; attempt to call a global(a nil value)

我是 Lua 的新手,正在關注https://wowwiki.fandom.com/wiki/AddOn_tutorial上的教程,但我無法讓它工作; 我已經復制了代碼,但在SetMapToCurrentZone()GetPlayerMapPosition("player")函數上都收到錯誤消息“嘗試調用全局‘函數名’(一個 nil 值) ”。

這是整個 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

我如何解決它?

這些函數在 8.0 中已被重命名並移至包裝器對象,分別為C_Map.GetBestMapForUnit (需要“player”作為參數以產生相同的結果)和C_Map.GetPlayerMapPosition

您可能會期望稍后調用的更多函數會拋出相同的錯誤,但之前無法訪問它們的行。 當我再次在桌面上時,我可以檢查整個代碼示例,但您可以簡單地在Wowpedia上查找這些函數,尤其是其他與地圖相關的函數。
我建議在 Wowwiki 上使用 Wowpedia,這是個人喜好/印象,前者似乎會收到更多不斷的更新。 (10年前分手后,兩人現在似乎又要合並了)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM