WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Error when using GetMapInfo (https://www.wowinterface.com/forums/showthread.php?t=56598)

Yukyuk 08-25-18 10:17 AM

Error when using GetMapInfo
 
I recently updated my addon Historia to BFA.
All is working fine but there is one error I can't solve.
Its when I get a loading screen and then end up in a zone I haven't been before.
I get an error.

Lua Code:
  1. 20x FrameXML\MapUtil.lua:11: Usage: local info = C_Map.GetMapInfo(uiMapID)
  2. [C]: in function `GetMapInfo'
  3. FrameXML\MapUtil.lua:11: in function `GetMapParentInfo'
  4. Historia\HistoriaMain.lua:326: in function `?'
  5. Historia\HistoriaMain.lua:146: in function <Historia\HistoriaMain.lua:145>
  6.  
  7. Locals:
  8. (*temporary) = nil


I understand the error but what I do not ouderstand is WHY I am getting it.
If statement in line 11 (line 326 in the full addon) should prevent it.
When executing the addon it will print the currentMapId as being nil
and it will print the number 1.

Think I must be missing something here :confused:

Lua Code:
  1. function private_table.eventFrame:UI_INFO_MESSAGE(...)
  2.     local arg1, arg2 = ...
  3.     --print(arg1)
  4.     --print(arg2)
  5.     addon:Check_Dates()
  6.     if arg1 == 371 then
  7.         local zone = {}
  8.         zone.time = time()
  9.         local currentMapId, TOP_MOST = C_Map.GetBestMapForUnit('player'), true
  10.         print(currentMapId)
  11.         if currentMapId == nil then
  12.             print("1")
  13.             local zone = {}
  14.         else
  15.             print("2")
  16.             local currentContinentInfo = MapUtil.GetMapParentInfo(currentMapId, Enum.UIMapType.Continent, TOP_MOST)
  17.             print(currentContinentInfo)
  18.             zone.continent = currentContinentInfo.name
  19.             zone.zoneName = GetZoneText()
  20.             zone.subzoneName = GetSubZoneText()
  21.             table.insert(HistoriaLocalDb.Area, zone)
  22.             --  Insert new area in the dates table
  23.             table.insert(HistoriaLocalDb.Dates[addon.YS][addon.MS][addon.DS].Area, zone)
  24.         end
  25.     elseif arg1 == 280 then
  26.         local flight = {}
  27.         flight.time = time()       
  28.         local currentMapId, TOP_MOST = C_Map.GetBestMapForUnit('player'), true
  29.         local currentContinentInfo = MapUtil.GetMapParentInfo(currentMapId, Enum.UIMapType.Continent, TOP_MOST)
  30.         flight.continent = currentContinentInfo.name       
  31.         flight.zoneName = GetZoneText()
  32.         flight.subzoneName = GetSubZoneText()
  33.         table.insert(HistoriaLocalDb.Taxi, flight)
  34.         --  Insert new flight path in the dates table
  35.         table.insert(HistoriaLocalDb.Dates[addon.YS][addon.MS][addon.DS].Taxi, flight) 
  36.     end    
  37. end

semlar 08-25-18 12:33 PM

You aren't checking if currentMapId is nil the second time you call the function.

Yukyuk 08-25-18 01:37 PM

@Semlar
You lost me there.
What second time?

semlar 08-25-18 03:01 PM

You call MapUtil.GetMapParentInfo twice in your code; once in the first block, after checking that currentMapId is not nil, and again later on without checking it.

We don't have your whole code so don't have the line numbers, but it's fully possible that the first block is executing correctly, followed by the second block throwing the error.

Vrul 08-25-18 03:44 PM

Since both cases are basically identical in how they are handled:
Code:

function private_table.eventFrame:UI_INFO_MESSAGE(messageType)
    local dbKey
    if messageType == 371 then      -- New Area
        dbKey = "Area"
    elseif messageType == 280 then  -- New Taxi Path
        dbKey = "Taxi"
    end
    if dbKey then
        local mapID = C_Map.GetBestMapForUnit('player')
        if mapID then
            addon:Check_Dates()
            local continentInfo = MapUtil.GetMapParentInfo(mapID, Enum.UIMapType.Continent, true)
            local data = {
                time        = time(),
                continent  = continentInfo.name,
                zoneName    = GetZoneText(),
                subzoneName = GetSubZoneText()
            }
            table.insert(HistoriaLocalDb[dbKey], data)
            table.insert(HistoriaLocalDb.Dates[addon.YS][addon.MS][addon.DS][dbKey], data)
        end
    end
end

I just guessed that addon:Check_Dates() only needed to run when saving data so move it if needed.

Yukyuk 08-26-18 03:42 AM

Solved
 
Thank you Vrul.
Its working now.
Also taught me a bit about more effecient coding :)


All times are GMT -6. The time now is 06:05 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI