Thread Tools Display Modes
08-30-17, 04:21 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Archaeology race info

I thought I'd save the returns from GetArchaeologyRaceInfo() now that it has changed. Just a little utility to poke at for data later.

But I have a bug in my code which I can't spot. It keeps saying my SV is nil.
Lua Code:
  1. 1x ARI73\ARI73-1.0.lua:13: attempt to index global 'ARI73DB' (a nil value)
  2. ARI73\ARI73-1.0.lua:13: in function `?'
  3. ARI73\ARI73-1.0.lua:34: in function <ARI73\ARI73.lua:33>
Here is my ToC file:
Lua Code:
  1. ## Interface: 70300
  2. ## Title: Archaeology Race Info 7.3
  3. ## Notes: Utility to save the new return values of the API
  4. ## Author: Paul "Myrroddin" Vandersypen
  5. ## Version: 1.0
  6. ## SavedVariables: ARI73DB
  7.  
  8. ARI73.lua
and the main addon
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("ADDON_LOADED")
  5. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  6.  
  7. function addon:PLAYER_ENTERING_WORLD()
  8.     local raceCount = GetNumArchaeologyRaces()
  9.  
  10.     for i = 1, raceCount do
  11.         local raceName, textureID, itemID, numFragsCol, numFragsReq, maxFrags = GetArchaeologyRaceInfo(i)
  12.         local keystoneName = GetItemInfo(itemID)
  13.         ARI73DB[raceName] = ARI73DB[raceName] or {}
  14.  
  15.         ARI73DB[raceName]["raceIndex"] = i or 0
  16.         ARI73DB[raceName]["textureID"] = textureID or 0
  17.         ARI73DB[raceName]["keystoneID"] = itemID or 0
  18.         ARI73DB[raceName]["keystoneName"] = keystoneName or ""
  19.         ARI73DB[raceName]["maxFragments"] = maxFrags or 0
  20.     end
  21.     f:UnregisterEvent("PLAYER_ENTERING_WORLD")
  22. end
  23.  
  24. function addon:ADDON_LOADED(event, name)
  25.     if name ~= addonName then
  26.         return
  27.     end
  28.  
  29.     ARI73DB = ARI73DB or {}
  30.     f:UnregisterEvent("ADDON_LOADED")
  31. end
  32.  
  33. f:SetScript("OnEvent", function(self, event, ...)
  34.     addon[event](self, ...)
  35. end)
  Reply With Quote
08-30-17, 04:34 PM   #2
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
What happens if you put the function addon:ADDON_LOADED(event, name) above the addon:PLAYER_ENTERING_WORLD() function?

Which event fires first?

If PEW fires first, it is trying to index a non existent table for first time users and is the reason for your error. Therefore that line ARI73DB = ARI73DB or {} in your ADDON_LOADED function needs to happen before you start writing data to it.

Last edited by Terenna : 08-30-17 at 04:41 PM.
  Reply With Quote
08-30-17, 05:41 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Oh, I bet you are correct. I suspect PEW does fire before AL. I'll fix and test.

Alright, I have fixed that issue, but the SV is still nil. However, the error is gone.
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local f = CreateFrame("Frame")
  4. f:RegisterEvent("ADDON_LOADED")
  5.  
  6. function addon:GetData()
  7.     local raceCount = GetNumArchaeologyRaces()
  8.  
  9.     for i = 1, raceCount do
  10.         local raceName, textureID, itemID, numFragsCol, numFragsReq, maxFrags = GetArchaeologyRaceInfo(i)
  11.         local keystoneName = GetItemInfo(itemID)
  12.         ARI73DB[raceName] = ARI73DB[raceName] or {}
  13.  
  14.         ARI73DB[raceName]["raceIndex"] = i or 0
  15.         ARI73DB[raceName]["textureID"] = textureID or 0
  16.         ARI73DB[raceName]["keystoneID"] = itemID or 0
  17.         ARI73DB[raceName]["keystoneName"] = keystoneName or ""
  18.         ARI73DB[raceName]["maxFragments"] = maxFrags or 0
  19.     end
  20. end
  21.  
  22. function addon:ADDON_LOADED(event, name)
  23.     if name ~= addonName then
  24.         return
  25.     end
  26.  
  27.     ARI73DB = ARI73DB or {}
  28.     addon:GetData()
  29.     f:UnregisterEvent("ADDON_LOADED")
  30. end
  31.  
  32. f:SetScript("OnEvent", function(self, event, ...)
  33.     addon[event](self, ...)
  34. end)

Last edited by myrroddin : 08-30-17 at 06:28 PM. Reason: updated code
  Reply With Quote
08-30-17, 05:54 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Essentialy when the code runs is when the addon is being loaded so the ADDON_LOADED event is pretty much redundant save for XML frames.

You can check for saved variables in the PLAYER_LOGIN event which only fires once after all addons are loaded and before PEW.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-31-17 at 12:19 AM.
  Reply With Quote
08-30-17, 06:30 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Fizzlemizz View Post
You can check for saved variables in the PLAYER_LOGIN event which only fires once and after your addon is loaded and before PEW.
I should have refreshed the thread before editing the above! Hang on, I will test with PL instead.

EDIT: success!! Thank you Fizzlemizz!!

If you want to know the data, here is the contents of my saved variables file:
Lua Code:
  1. ARI73DB = {
  2.     ["Nerubian"] = {
  3.         ["raceIndex"] = 14,
  4.         ["keystoneID"] = 64396,
  5.         ["textureID"] = 461835,
  6.         ["keystoneName"] = "Nerubian Obelisk",
  7.         ["maxFragments"] = 0,
  8.     },
  9.     ["Fossil"] = {
  10.         ["raceIndex"] = 16,
  11.         ["keystoneID"] = 0,
  12.         ["textureID"] = 461833,
  13.         ["keystoneName"] = "",
  14.         ["maxFragments"] = 0,
  15.     },
  16.     ["Highmountain Tauren"] = {
  17.         ["raceIndex"] = 2,
  18.         ["keystoneID"] = 130904,
  19.         ["textureID"] = 1445577,
  20.         ["keystoneName"] = "Highmountain Ritual-Stone",
  21.         ["maxFragments"] = 200,
  22.     },
  23.     ["Ogre"] = {
  24.         ["raceIndex"] = 4,
  25.         ["keystoneID"] = 109584,
  26.         ["textureID"] = 1030618,
  27.         ["keystoneName"] = "Ogre Missive",
  28.         ["maxFragments"] = 250,
  29.     },
  30.     ["Troll"] = {
  31.         ["raceIndex"] = 11,
  32.         ["keystoneID"] = 63128,
  33.         ["textureID"] = 461841,
  34.         ["keystoneName"] = "",
  35.         ["maxFragments"] = 0,
  36.     },
  37.     ["Pandaren"] = {
  38.         ["raceIndex"] = 8,
  39.         ["keystoneID"] = 79868,
  40.         ["textureID"] = 633002,
  41.         ["keystoneName"] = "",
  42.         ["maxFragments"] = 0,
  43.     },
  44.     ["Mogu"] = {
  45.         ["raceIndex"] = 7,
  46.         ["keystoneID"] = 79869,
  47.         ["textureID"] = 633000,
  48.         ["keystoneName"] = "",
  49.         ["maxFragments"] = 0,
  50.     },
  51.     ["Draenei"] = {
  52.         ["raceIndex"] = 17,
  53.         ["keystoneID"] = 64394,
  54.         ["textureID"] = 461829,
  55.         ["keystoneName"] = "Draenei Tome",
  56.         ["maxFragments"] = 0,
  57.     },
  58.     ["Demonic"] = {
  59.         ["raceIndex"] = 1,
  60.         ["keystoneID"] = 130905,
  61.         ["textureID"] = 1445573,
  62.         ["keystoneName"] = "",
  63.         ["maxFragments"] = 0,
  64.     },
  65.     ["Mantid"] = {
  66.         ["raceIndex"] = 9,
  67.         ["keystoneID"] = 95373,
  68.         ["textureID"] = 839111,
  69.         ["keystoneName"] = "",
  70.         ["maxFragments"] = 0,
  71.     },
  72.     ["Dwarf"] = {
  73.         ["raceIndex"] = 18,
  74.         ["keystoneID"] = 52843,
  75.         ["textureID"] = 461831,
  76.         ["keystoneName"] = "",
  77.         ["maxFragments"] = 0,
  78.     },
  79.     ["Tol'vir"] = {
  80.         ["raceIndex"] = 12,
  81.         ["keystoneID"] = 64397,
  82.         ["textureID"] = 461839,
  83.         ["keystoneName"] = "",
  84.         ["maxFragments"] = 0,
  85.     },
  86.     ["Night Elf"] = {
  87.         ["raceIndex"] = 15,
  88.         ["keystoneID"] = 63127,
  89.         ["textureID"] = 461837,
  90.         ["keystoneName"] = "",
  91.         ["maxFragments"] = 0,
  92.     },
  93.     ["Highborne"] = {
  94.         ["raceIndex"] = 3,
  95.         ["keystoneID"] = 130903,
  96.         ["textureID"] = 1445575,
  97.         ["keystoneName"] = "Ancient Suramar Scroll",
  98.         ["maxFragments"] = 200,
  99.     },
  100.     ["Orc"] = {
  101.         ["raceIndex"] = 13,
  102.         ["keystoneID"] = 64392,
  103.         ["textureID"] = 462321,
  104.         ["keystoneName"] = "",
  105.         ["maxFragments"] = 0,
  106.     },
  107.     ["Vrykul"] = {
  108.         ["raceIndex"] = 10,
  109.         ["keystoneID"] = 64395,
  110.         ["textureID"] = 461843,
  111.         ["keystoneName"] = "",
  112.         ["maxFragments"] = 0,
  113.     },
  114.     ["Arakkoa"] = {
  115.         ["raceIndex"] = 6,
  116.         ["keystoneID"] = 109585,
  117.         ["textureID"] = 1030616,
  118.         ["keystoneName"] = "Arakkoa Cipher",
  119.         ["maxFragments"] = 250,
  120.     },
  121.     ["Draenor Clans"] = {
  122.         ["raceIndex"] = 5,
  123.         ["keystoneID"] = 108439,
  124.         ["textureID"] = 1030617,
  125.         ["keystoneName"] = "Draenor Clan Orator Cane",
  126.         ["maxFragments"] = 250,
  127.     },
  128. }

Last edited by myrroddin : 08-30-17 at 06:54 PM. Reason: Very nice, great success!
  Reply With Quote
08-30-17, 07:01 PM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
One thing to note: I haven't unlocked all the races' archaeology on my Demon Hunter yet, therefore, your "maxFragments" may vary. It seems to default to nil or 0 if that is the case.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Archaeology race info


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