简体   繁体   中英

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

I'm new to Lua and was following the tutorial on https://wowwiki.fandom.com/wiki/AddOn_tutorial but i just cant get it to work; i have copied the code but i get the error message " attempt to call a global 'functionname' (a nil value) " on both the SetMapToCurrentZone() and the GetPlayerMapPosition("player") functions.

This is the entire Lua file;

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

How do i fix it?

These functions have been renamed and moved to a wrapper object in 8.0, to C_Map.GetBestMapForUnit (requiring "player" as parameter to yield the same result) and C_Map.GetPlayerMapPosition respectively.

You can probably expect more functions that are called later to throw the same error, their lines just couldn't be reached before. I can check the whole code example when I'm at a desktop again, but you may simply look up these functions on Wowpedia , especially other map-related functions.
I suggest using Wowpedia over Wowwiki, it's a personal preference/impression, the former seems to receive more constant updates. (The two seem to be merging again now, after splitting 10 years ago)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM