Thread Tools Display Modes
08-25-18, 10:17 AM   #1
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
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

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
__________________
Better to fail then never have tried at all.
  Reply With Quote
08-25-18, 12:33 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You aren't checking if currentMapId is nil the second time you call the function.
  Reply With Quote
08-25-18, 01:37 PM   #3
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
@Semlar
You lost me there.
What second time?
__________________
Better to fail then never have tried at all.
  Reply With Quote
08-25-18, 03:01 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
  Reply With Quote
08-25-18, 03:44 PM   #5
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
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.
  Reply With Quote
08-26-18, 03:42 AM   #6
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
Solved

Thank you Vrul.
Its working now.
Also taught me a bit about more effecient coding
__________________
Better to fail then never have tried at all.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Error when using GetMapInfo

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off