Quantcast Table Structure in a Saved Variable - Page 2 - WoWInterface
Thread Tools Display Modes
12-30-17, 12:27 PM   #21
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 883
Code:
Do variables created inside a local function need the local?
Vairables don't need to be local but as people tend to use throw away names, making them all global would be disasterous

Local is only local within the "chunk"(lua file, function, if, for etc.) it's defined so create them as the need (scope) requires.
Code:
local var1 = "A"
if SomeCondition then
    local var1 = "B"
    print(var1) -- prints B
end
print(var1) -- prints A
Code:
AddonListDB = {}
Now you've got me condfused, you're creating a new AddonListDB each time?
Code:
AddonListDB = AddonListDB  or {}
Code:
if (loaded ~= AddonListDB[i].Loaded) or ((loaded == true) and (AddonListDB[i].Loaded == true)) then
This is going to cause you problems. Because you're comparing/adding to AddonListDB using the order id from GetNumAddOns() and not checking if the addon in that slot is actually the one returned by GetAddOnInfo(i) or the other functions.

You can't be sure you're comparing the same addon ie. if you add or remove an addon or a multi addon addon adds/removes one of it's addon folders or a dependancy changes then the order you last saved the table won't be the same as the current order you're checking.

If saved something like:
Code:
 AddonListDB[title] = {
        Loaded=loaded or false,
        Dependencies=dep1 or false,
        OptionalDependencies=odep1 or false,
        LoadOnDemand=ldemand or false,
        DateTime=date("%m/%d/%y %H:%M:%S")
};
You could.
Code:
local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
if AddonListDB[title] then
-- the addon is not a new one so update it
else
-- add the new addon information
end
You would need to check if any of the last saved addons are no longer being used.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle and Move Pad Plus.

Last edited by Fizzlemizz : 12-30-17 at 01:25 PM.
  Reply With Quote
12-30-17, 05:28 PM   #22
JDoubleU00
A Rage Talon Dragon Guard
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 330
Success

I think I have it working. I've ran several tests and things seem to update or not update correctly. It took me a while to figure out how to compare a Boolean and correctly list the table fields (I think it is slowly sinking in). Anyway, here is the finished code, of course I have to write the code that will do the reminder, but that is for another day, I have to finish packing and move Sunday. I know, coding while moving? It is a good distraction for me.

Again a big thanks to Fizzlemizz for the hekp!

Lua Code:
  1. local addonlistdb
  2.  
  3. local function PLAYER_LOGOUT()
  4.     AddonListDB = AddonListDB or {}
  5.     addonlistdb = AddonListDB
  6.     local addcount = GetNumAddOns()
  7.     for i = 1,addcount do --use the numeric index to loop through all the addons
  8.         local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  9.         loaded, finished = IsAddOnLoaded(i)
  10.         local dep1, dep2, dep3 = GetAddOnDependencies(i)
  11.         local odep1 = GetAddOnOptionalDependencies(i)
  12.         local ldemand = IsAddOnLoadOnDemand(i)
  13.         if AddonListDB[title] then --use the title of the addon to make sure the correct addon is updated
  14.             --addon is not new, update the info is the load state is different
  15.             if tostring(loaded or false) ~= tostring(AddonListDB[title].Loaded) then
  16.                 AddonListDB[title] = {
  17.                     Loaded=loaded or false,
  18.                     Dependencies=dep1 or false,
  19.                     OptionalDependencies=odep1 or false,
  20.                     LoadOnDemand=ldemand or false,
  21.                     DateTime=date("%m/%d/%y %H:%M:%S")
  22.                 };
  23.             end
  24.         else
  25.             --addon does not exist, add the information
  26.             AddonListDB[title] = {
  27.                 Loaded=loaded or false,
  28.                 Dependencies=dep1 or false,
  29.                 OptionalDependencies=odep1 or false,
  30.                 LoadOnDemand=ldemand or false,
  31.                 DateTime=date("%m/%d/%y %H:%M:%S")
  32.             };
  33.         end
  34.     end
  35. end
  36.  
  37. local JWFrame = CreateFrame("Frame");
  38. JWFrame:RegisterEvent("PLAYER_LOGOUT");
  39. JWFrame:SetScript("OnEvent", PLAYER_LOGOUT);

Of course, there might still be errors. <shrugs>
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote

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

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