Hi,
Sorry this is so long.
I read somewhere that if your saving a table and in a new version of your addon u add something to the table. If someone who had saved variables from your old version installed the new one, the new key u added to the table would not be saved. Understand? lol
I.e. If I had this in version 1:
Code:
Table = { key1 = "value1", key2 = "value2" }
and in version 2 I had:
Code:
Table = { key1 = "value1", key2 = "value2", key3 = "value3" }
if someone used version 1 and upgraded to version 2 without deleting their saved variables, the key3 wouldnt be saved each time they logged out. Or so I've read.
Where ever I read this also said to fix the problem make a table with the default keys and values and use the following:
Code:
for key, value in pairs(Table_Defaults) do
if (not Table[key]) then
FF_Options[key] = value;
end
end
First of all, is this true?
I have done what I said above, but my table is always replaced with the default so my variables never load the saved ones.
I have the following in my TOC file:
Code:
## SavedVariables: FF_Options
and then in the OnLoad event i have:
Code:
this:RegisterEvent("ADDON_LOADED");
and in the OnEvent I have:
Code:
if (event == "ADDON_LOADED") then
if (arg1 == "AddOnName") then --My AddOn name is in the " "
FF_LoadVariables();
end
end
I have the following in the FF_LoadVariables() function:
Code:
for key, value in pairs(FF_Options_Defaults) do
if (not FF_Options[key]) then
FF_Options[key] = value;
end
end
Here is an example of my options tables (they are not in any function, just at the beginning of the lua file):
Code:
FF_Options_Defaults = {
['Option1'] = true,
['Option2'] = true,
['Option3'] = true,
['Option4'] = true,
['Option5'] = true
}
FF_Options = {
['Option1'] = true,
['Option2'] = true,
['Option3'] = true,
['Option4'] = true,
['Option5'] = true
}
If I use:
Code:
DEFAULT_CHAT_FRAME:AddMessage(table.getn(FF_Options))
in the FF_LoadVariables() function before it runs the for loop I get 0 printed to the default chat frame. This suggests that the table wasnt loaded. But if I go to the SavedVariables folder for my account and check the variables file for my addon the table is saved...
Also if I completely remove the loop the variables load to what ever they were saved as...
So what I want to know is:
Is what I read about the new key in the table not being saved true?
Why are the default variables always being loaded? OR Why dont any keys exist in FF_Options after the ADDON_LOADED event fires?