Thread Tools Display Modes
Prev Previous Post   Next Post Next
12-26-17, 03:28 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Table Structure in a Saved Variable

I'm writting an addon that creates a savedvariable with a table of all addons and if they are enabled or disabled. The addon works, but I am not understanding the how the table structure is created. What I expexcted and what is written are two entirely different things. If someone could shed some light on this, it would be greatly appreciated. Following is the code involved and a snippet of the saved variable.

Lua Code:
  1. ## Interface: 70300
  2. ## Title: AddonList
  3. ## SavedVariables: AddonListDB
  4. ## DefaultState: disabled
  5.  
  6. AddonList.lua

Lua Code:
  1. local addonlistdb
  2. local JWFrame = CreateFrame("Frame");
  3.  
  4. function dostuff()
  5.     print("Do stuff")
  6.     --for i = 1,addcount do
  7.         --local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  8.         --AddonListDB[i] = {title,IsAddonLoaded}
  9.         --print(title, IsAddOnLoaded(i))
  10.     --end
  11.     --print(#addlist..\" addons\")
  12.     --for k,v in ipairs(AddonListDB) do
  13.         --print(k,v[2],v[3])
  14.     --end
  15. end
  16.  
  17. JWFrame:RegisterEvent("ADDON_LOADED");
  18.  
  19. JWFrame:SetScript("OnEvent", function(self, event, arg1)
  20.     if event == "ADDON_LOADED" and arg1 == "AddonList" then
  21.         addonlistdb = AddonListDB
  22.         -- Our saved variables, if they exist, have been loaded at this point.
  23.         if AddonListDB == nil then
  24.             print("No saved variables")
  25.             AddonListDB = {}
  26.         else
  27.             print("Saved variables exist")
  28.             local addcount = GetNumAddOns()
  29.             for i = 1,addcount do
  30.                 local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  31.                 loaded, finished = IsAddOnLoaded(i)
  32.                 AddonListDB[i] = {title,loaded}
  33.                 --print(i,title,loaded)
  34.             end
  35.         end
  36.     end
  37.     print("Did stuff")
  38. end)
  39.  
  40. SlashCmdList["ADDONLIST"] = function() dostuff() end
  41. SLASH_ADDONLIST1 = "/al"

Ignore the comments, I am experimenting with code and a slash command.


Lua Code:
  1. AddonListDB = {
  2.     {
  3.         "!!!Ease Addon Controller", -- [1]
  4.         false, -- [2]
  5.     }, -- [1]
  6.     {
  7.         "!!AceDB-DefaultMod", -- [1]
  8.         true, -- [2]
  9.     }, -- [2]
  10.     {
  11.         "_Cursor", -- [1]
  12.         false, -- [2]
  13.     }, -- [3]
  14.  
  15.         395, -- [1]
  16.         "PictureThis", -- [2]
  17.         "|cffFF7700Picture|cff0055FFThis", -- [3]
  18.     }, -- [395]
  19.     {
  20.         396, -- [1]
  21.         "sFilter", -- [2]
  22.         "|cFFFFFFFFs|r|cFFFF8C00F|r|cFFFFFFFFilter Spells|r", -- [3]
  23.     }, -- [396]

What I was expecting in the saved variable is the addon name and if it is loaded/enabled. The first few entries confirm this, but some addons do not have true or false, it lists the title as seen by the last few entries. I am not sure why this is happening.

Also, where do the commented out numbers come from? The -- [1] etc...

Thanks and I hope everyone is enjoying the holidays no matter how you celebrate it.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
 

WoWInterface » Developer Discussions » General Authoring Discussion » Table Structure in a Saved Variable


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