View Single Post
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: 1,879
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, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-30-17 at 01:25 PM.
  Reply With Quote