Thread Tools Display Modes
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
12-26-17, 04:20 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
The numbers come from when the game exports a table (SavedVariable) without labels specified for keys
Code:
{
  [1] = "Something",
  [2] = "Something else",
}
Code:
{
  "Something",
  "Something else",
}
will be saved as
Code:
{
  "Something", -- [1]
  "Something else", -- [2]
}
You would be better served doing your initial check at PLAYER_LOGIN after ALL the startup addons have had a chance to load.

Using ADDON_LOADED (with your addon as the execution marker) will show all the addons that have been loaded prior to yours (and if they were succesful or not) and addons that are still to be loaded (after yours) but at this point, it is undetermined if they will load.

You can use ADD_LOADED to check for addons that load during play (Load On Demand) ie. register the event after you've done your check at PLAYER_LOGIN.

Edit:
but some addons do not have true or false
IsAddonLoaded returns true or nil. A table entry of nil doesn't exists so:
Code:
AddonListDB[i] = {title,loaded}
will only show an entry for "loaded" when it is true.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-26-17 at 05:46 PM.
  Reply With Quote
12-26-17, 10:26 PM   #3
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Thanks for clarifying things for me. I'm reworking my code, but have a question on how to handle nil for a table value. Is there a Lua function or some other way to trap nil and replace it with a string value that would work in a table? I've tried GoogleFu, but I only found confusing information.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-26-17, 10:37 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Code:
local TestTable = {
   label1 = "something", 
   Otherthing = "something else",
}

if not TestTable.CheckKey then
    -- TestTable.CheckKey is either nil (doesn't exist) or false
end
I'm not sure if this is what you are looking for.

In your code you could still do:
Code:
if not AddonListDB[i].loaded then
      -- the addon wasn't loaded so ...
end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-26-17 at 10:49 PM.
  Reply With Quote
12-27-17, 01:33 PM   #5
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Thanks again for your replies, I realized that I should stop asking questions when I am tired, They make less sense to everyone.

I may have not wrote the addon correctly, it works sort of. Here are more questions that hopefully will set off the light bulb above my head. I really have tried Google, but I welcome links to the appropriate topic.

1. How could I replace the nil value in loaded with a string that a table would like for this code? In the event the addon was not loaded.
Lua Code:
  1. loaded, finished = IsAddOnLoaded(i)
  2. AddonListDB[i] = {title,loaded}

2. I've tried a lot of different methods to set labels for table entries, with no luck. What am I missing so that I could have something like this:
Lua Code:
  1. {[name] = "Addon Name",
  2. [loaded] = "Addon Loaded"}

3. It has dawned on me that I might need to use the local saved variable instead of the one listed in the .TOC. This line seems essential.
Lua Code:
  1. addonlistdb = AddonListDB

4. Finally, is there any advantage to using Lua table methods like table.insert versus savedvariable[i] = "something"?
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-27-17, 01:48 PM   #6
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Lua Code:
  1. AddonListDB[i] = {title,loaded or false}

This is a sort of shortcut on how Lua parses. This is called a ternary operator. If loaded is true or has a value, that will be used. If loaded is false or nil, it will go to the second part, which is also false, which is what it will use.
  Reply With Quote
12-27-17, 02:23 PM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Code:
TestTable = {
    KeyName = "Some Value",
    ["OtherKeyName"] = "Some Other Value",
}
You can set/get a key directly by name or as a string using [].
Code:
print(TestTable.KeyName)
or if you have been given the name of a key as a string:
Code:
local key = "KeyName"
print(TestTable[key])
Code:
addonlistdb = AddonListDB
This is assigning a pointer to the global table AddonListDB to the local variable addonlistdb. While it seems like you are altering a local table you are actually altering the global table so whether you do
Code:
addonlistdb.loaded = true
or
AddonListDB.loaded = true
they are both settting AddonListDB.loaded to true.

tinsert allows you to assign a position and re-order if required whereas using savedvariable[i] = "something" will overwrite the i key if it exists.

As an aside your code:

Code:
       addonlistdb = AddonListDB
        -- Our saved variables, if they exist, have been loaded at this point.
        if AddonListDB == nil then
            print("No saved variables")
            AddonListDB = {}
every time you use
Code:
variable = {}
you create a new table
if you do addonlistdb = AddonListDB before the table is created then addonlistdb will be forever nil (unless you re-assign it).

if you do AddonListDB = {} after addonlistdb = AddonListDB (asuming AddonListDB existed) addonlistdb will be pointing to the old table until it is garbage collected.

A simple example of table pointers:
Code:
/run local t = {} local v = t print("A", t, v) v.k1 = 12 print("B", t.k1, v.k1) t = {} print("C", t, v)
In the first print() the table ids (references) will be the same, in the second print() t.k1 will also be 12 even though you only assigned it to v.k1. And in the last print, after the second t = {}, t will be a new reference (new table) and v remains as the old reference.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-27-17 at 03:01 PM.
  Reply With Quote
12-27-17, 07:45 PM   #8
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Solution!

OK, so after much reading, more Googling and so much trial and error, I have working code.

Lua Code:
  1. local addonlistdb
  2. local JWFrame = CreateFrame("Frame");
  3.  
  4. JWFrame:RegisterEvent("PLAYER_LOGIN");
  5.  
  6. JWFrame:SetScript("OnEvent", function(self, event, ...)
  7.     if self[event] then return self[event](self, ...)
  8.     end
  9. end);
  10.  
  11. function JWFrame:PLAYER_LOGIN()
  12.         AddonListDB = AddonListDB or {}
  13.         addonlistdb = AddonListDB
  14.         local addcount = GetNumAddOns()
  15.         for i = 1,addcount do
  16.             local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  17.             loaded, finished = IsAddOnLoaded(i)
  18.                 AddonListDB[i] = {
  19.                 Title=title,
  20.                 Loaded=loaded or false
  21.             };
  22.         end
  23. end

This generates the following saved variable file.

Lua Code:
  1. AddonListDB = {
  2.     {
  3.         ["Title"] = "!!!Ease Addon Controller",
  4.         ["Loaded"] = false,
  5.     }, -- [1]
  6.     {
  7.         ["Title"] = "!!AceDB-DefaultMod",
  8.         ["Loaded"] = true,
  9.     }, -- [2]
  10.     {
  11.         ["Title"] = "_Cursor",
  12.         ["Loaded"] = false,
  13.     }, -- [3]
  14.     {
  15.         ["Title"] = "Ackis Recipe List",
  16.         ["Loaded"] = false,
  17.     }, -- [4]
  18.     {
  19.         ["Title"] = "Ackis Recipe List: Alchemy",
  20.         ["Loaded"] = false,
  21.     }, -- [5]
  22.     {
  23.         ["Title"] = "Ackis Recipe List: Blacksmithing",
  24.         ["Loaded"] = false,
  25.     }, -- [6]
  26.     {
  27.         ["Title"] = "Ackis Recipe List: Cooking",
  28.         ["Loaded"] = false,
  29.     }, -- [7]

It currently only triggers on PLAYER_LOGIN, but I'll work on ADDON_LOADED later. I admit that I am slightly puzzled how the SetScript works in this case. I am more used to the usual SetScript("OnEvent", Function). Lua has multiple ways of doing things and for some reason, I find the language harder to get a handle on than other languages.

Any suggestions are still welcome. This is a good experience for me to learn more about tables and saved variables.

Thanks again.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-27-17, 08:25 PM   #9
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Just register ADDON_LOADED alongside PLAYER_LOGIN. OnEvent fires whenever any of the events registered to the frame happen.
I guess if you're doing it with separate functions for each event then you would also need to write the same one but for ADDON_LOADED. Though, for what you're doing, I'm honestly not sure why it needs to be separate from your OnEvent script.

(What does your script at lines 6-9 actually do, anyway?)
  Reply With Quote
12-27-17, 08:26 PM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
The SetScript is creating the function "in situ" rather than calling another function. Either way works although the SetScript("script", function) is better if multiple scripts can use the same function.

If you mean the
Code:
if self[event] then return self[event](self, ...)
then in this case, self is JWFrame so,
Code:
if JWFrame["PLAYER_LOGIN"] then return JWFrame["PLAYER_LOGIN"](self, ...)
calls
Code:
function JWFrame:PLAYER_LOGIN()
A frame is a secial type of table so you can add attributes (variables) and methods (functions) to it like you would a standard table.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-27-17, 08:35 PM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Originally Posted by Ammako View Post
Just register ADDON_LOADED alongside PLAYER_LOGIN. OnEvent fires whenever any of the events registered to the frame happen.
I guess if you're doing it with separate functions for each event then you would also need to write the same one but for ADDON_LOADED. Though, for what you're doing, I'm honestly not sure why it needs to be separate from your OnEvent script.

(What does your script at lines 6-9 actually do, anyway?)
ADDON_LOADED would have to be registered in the JWFrame:PLAYER_LOGIN() function so it is not activated every time a startup addon loads. You could
Code:
if not JWFrame.ADDON_LOADED  then
      JWFrame.ADDON_LOADED = JWFrame.PLAYER_LOGIN
      JWFrame:RegisterEvent("ADDON_LOADED")
end
But this means it is going to cycle through all addons each time the ADDON_LOADED event is fired (admittedly this won't be very often so the extra processing might not bother JDoubleU00)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-27-17 at 08:41 PM.
  Reply With Quote
12-27-17, 10:12 PM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
I should probably also point out, in case you aren't aware, that adding your onevent (or any) functions to your frame
Code:
function JWFrame:PLAYER_LOGIN()
...
end
you are making them global.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-27-17 at 10:57 PM.
  Reply With Quote
12-28-17, 12:32 PM   #13
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Fizzlemizz View Post
I should probably also point out, in case you aren't aware, that adding your onevent (or any) functions to your frame
Code:
function JWFrame:PLAYER_LOGIN()
...
end
you are making them global.
I wasn't aware of that, but it makes sense when you pointed it out. Globals are usually bad, my frame names are fairly unique, so that is not a problem. Is there a better way to write this?
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-28-17, 12:58 PM   #14
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
If you want to keep using the table lookup approach, you could use a local table rather than the frame.

Lua Code:
  1. local addonlistdb
  2.     local events = {}
  3.     function events.PLAYER_LOGIN(self, ...)
  4.             AddonListDB = AddonListDB or {}
  5.             addonlistdb = AddonListDB
  6.             local addcount = GetNumAddOns()
  7.             for i = 1,addcount do
  8.                 local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  9.                 loaded, finished = IsAddOnLoaded(i)
  10.                     AddonListDB[i] = {
  11.                     Title=title,
  12.                     Loaded=loaded or false
  13.                 };
  14.             end
  15.             if not events.ADDON_LOADED then
  16.                 events.ADDON_LOADED = events.PLAYER_LOGIN
  17.             end
  18.     end
  19.  
  20.     local JWFrame = CreateFrame("Frame");
  21.      
  22.     JWFrame:RegisterEvent("PLAYER_LOGIN");
  23.     JWFrame:RegisterEvent("ADDON_LOADED");
  24.     JWFrame:SetScript("OnEvent", function(self, event, ...)
  25.         if events[event] then return events[event](self, ...)
  26.         end
  27.     end);
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-28-17, 01:08 PM   #15
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Just having come to my seneses, unless you are looking up the information in-game during a session, you can run the process just once at PLAYER_LOGOUT.

Lua Code:
  1. local function PLAYER_LOGOUT()
  2.             AddonListDB = {}
  3.             local addcount = GetNumAddOns()
  4.             for i = 1,addcount do
  5.                 local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  6.                 loaded, finished = IsAddOnLoaded(i)
  7.                     AddonListDB[i] = {
  8.                     Title=title,
  9.                     Loaded=loaded or false
  10.                 };
  11.             end
  12.     end
  13.  
  14.     local JWFrame = CreateFrame("Frame");
  15.     JWFrame:RegisterEvent("PLAYER_LOGOUT");
  16.     JWFrame:SetScript("OnEvent", PLAYER_LOGOUT)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-28-17 at 01:20 PM.
  Reply With Quote
12-28-17, 10:19 PM   #16
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Fizzlemizz View Post
Just having come to my seneses, unless you are looking up the information in-game during a session, you can run the process just once at PLAYER_LOGOUT.

Lua Code:
  1. local function PLAYER_LOGOUT()
  2.             AddonListDB = {}
  3.             local addcount = GetNumAddOns()
  4.             for i = 1,addcount do
  5.                 local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  6.                 loaded, finished = IsAddOnLoaded(i)
  7.                     AddonListDB[i] = {
  8.                     Title=title,
  9.                     Loaded=loaded or false
  10.                 };
  11.             end
  12.     end
  13.  
  14.     local JWFrame = CreateFrame("Frame");
  15.     JWFrame:RegisterEvent("PLAYER_LOGOUT");
  16.     JWFrame:SetScript("OnEvent", PLAYER_LOGOUT)
This seems to work quite well. I'm curious, wouldn't I need these two lines? Otherwise, it seems that line two would always wipe the saved variable.

AddonListDB = AddonListDB or {}
addonlistdb = AddonListDB

In any event, I really appreciate your help.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-28-17, 10:56 PM   #17
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Originally Posted by JDoubleU00 View Post
I'm curious, wouldn't I need these two lines? Otherwise, it seems that line two would always wipe the saved variable.

AddonListDB = AddonListDB or {}
addonlistdb = AddonListDB
I'm not sure what you are trying to achieve or may have planned to-do so much of my thinking is just a "stab in the dark".

Consider, you login one day with 24 addons, you exit. The next day you decide you only need 17 of them. Keeping the SavedVariable information from the previous day intact means that slots 18-24 will contain stale and possibly duplicate (possibly incorrect) information as they won't be overwritten using the new list of only 17 addons. Wiping the table each time means you have current data.

With the code you've given,
Code:
local addonlistdb
...
addonlistdb = AddonListDB
so far is not needed as you have been writing directly to AddonListDB (addonlistdb is just a pointer to AddonListDB, not a copy of the table)
Code:
AddonListDB = AddonListDB or {}
is all you need if you want to preserve the data between sessions.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-28-17 at 11:17 PM.
  Reply With Quote
12-29-17, 08:25 PM   #18
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Fizzlemizz View Post
I'm not sure what you are trying to achieve or may have planned to-do so much of my thinking is just a "stab in the dark".

Consider, you login one day with 24 addons, you exit. The next day you decide you only need 17 of them. Keeping the SavedVariable information from the previous day intact means that slots 18-24 will contain stale and possibly duplicate (possibly incorrect) information as they won't be overwritten using the new list of only 17 addons. Wiping the table each time means you have current data.

With the code you've given,
Code:
local addonlistdb
...
addonlistdb = AddonListDB
so far is not needed as you have been writing directly to AddonListDB (addonlistdb is just a pointer to AddonListDB, not a copy of the table)
Code:
AddonListDB = AddonListDB or {}
is all you need if you want to preserve the data between sessions.
/facepalm

I forgot the golden rule when asking for help, tell them what you are trying to do. So, my grand idea is thr following:

1. Get list of all addons at PLAYER_LOGOUT (I liked your suggestion).
2. Next time you logout of the game, compare your current addon state (enabled or disabled) to the old list.
3. Update the date/time stamp (see code below, minor modification) if the current addon state is different from the old data.
4. NOT IMPLEMENTD YET: At defined intervals, remind player that an addon has not been used for x period of time, say 30 days.
5. This helps the player decide if they still want the addon installed.

Why? I frequently install and addon and eventually stop using it, I'd like a reminder to uninstall it due to lack of use.

Lua Code:
  1. AddonListDB[i] = {
  2.                 Title=title,
  3.                 Loaded=loaded or false,
  4.                 DateTime=date("%m/%d/%y %H:%M:%S")
  5.             };

Lua Code:
  1. AddonListDB = {
  2.     {
  3.         ["Loaded"] = false,
  4.         ["Title"] = "!!!Ease Addon Controller",
  5.         ["DateTime"] = "12/29/17 00:26:23",
  6.     }, -- [1]

I need to work up the compare logic and then later the reminder mechanism. Is this a good approach to what I am trying to accomplish? Maybe there are better ways to do this.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
12-30-17, 12:52 AM   #19
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Originally Posted by JDoubleU00 View Post
I frequently install and addon and eventually stop using it, I'd like a reminder to uninstall it due to lack of use.
A lot of the "how" your logic might work would depend on if the addon is solely for your own use or not (you did say "I frequently").

You can make a lot of assumtions about the definition of how "useful" an addon is if it is just for your own use.

Some addon configs are seperate addons that are LOD but may be "useful" occaisionally.
Addons that are tagged "LoadWith" might not load every time but might still be "useful".
Every addon that loads by default may not be "useful".

Sorry, it's the devil's advocate in me, you may well have this covered.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-30-17 at 01:02 AM.
  Reply With Quote
12-30-17, 11:11 AM   #20
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Fizzlemizz View Post
A lot of the "how" your logic might work would depend on if the addon is solely for your own use or not (you did say "I frequently").

You can make a lot of assumtions about the definition of how "useful" an addon is if it is just for your own use.

Some addon configs are seperate addons that are LOD but may be "useful" occaisionally.
Addons that are tagged "LoadWith" might not load every time but might still be "useful".
Every addon that loads by default may not be "useful".

Sorry, it's the devil's advocate in me, you may well have this covered.
Heh, I like playing devil's advocate. I have thought of some of these situations. The LOD and LoadWith I did not.

Do variables created inside a local function need the local?

My thought for the date is compare current addon load state with the savedvariable and update if it is different (i.e. loaded and not loaded). I'll worry about the LOD and LoadWith later. If they are both disabled, do not update the date/time. This will give me a semi accurate idea of when it was last loaded. For the most part, this should work except for what we mentioned.

I'm trying this code for the logic, but I'm not quite getting it right.

Lua Code:
  1. local addonlistdb
  2.  
  3. local function PLAYER_LOGOUT()
  4.     AddonListDB = {}
  5.     local addcount = GetNumAddOns()
  6.     for i = 1,addcount do
  7.         local name, title, notes, loadable, reason, security, newVersion = GetAddOnInfo(i)
  8.         loaded, finished = IsAddOnLoaded(i)
  9.         local dep1, dep2, dep3 = GetAddOnDependencies(i)
  10.         local odep1 = GetAddOnOptionalDependencies(i)
  11.         local ldemand = IsAddOnLoadOnDemand(i)
  12.         if (loaded ~= AddonListDB[i].Loaded) or ((loaded == true) and (AddonListDB[i].Loaded == true)) then
  13.             AddonListDB[i] = {
  14.                 Title=title,
  15.                 Loaded=loaded or false,
  16.                 Dependencies=dep1 or false,
  17.                 OptionalDependencies=odep1 or false,
  18.                 LoadOnDemand=ldemand or false,
  19.                 DateTime=date("%m/%d/%y %H:%M:%S")
  20.             };
  21.         elseif (loaded == nil) and (AddonListDB[i].Loaded) == false then
  22.             AddonListDB[i] = {
  23.                 Title=title,
  24.                 Loaded=loaded or false,
  25.                 Dependencies=dep1 or false,
  26.                 OptionalDependencies=odep1 or false,
  27.                 LoadOnDemand=ldemand or false
  28.             };
  29.         end
  30.     end
  31. end
  32.  
  33. local JWFrame = CreateFrame("Frame");
  34. JWFrame:RegisterEvent("PLAYER_LOGOUT");
  35. JWFrame:SetScript("OnEvent", PLAYER_LOGOUT)
__________________
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