I'm trying to create savable profiles for all of my addons settings. I've gotten everything to work, with one small problem. The table changes when I reload the UI. It might be easiest if I just explain what I did.
A user pushes a button which runs some code & I attempted to copy the saved variable table into another table so it could be reloaded later.
I tried to create a copy of the table using (spoiler is code used to copy the table):
That created a copy and it worked just fine, until I reloaded the UI.
Heres what the tables (saved profiles) look like before & after I reload the UI.
Profile 2 on the left shows what it looks like after I create a new profile, before I reload the UI.
Profile 1 on the right shows what it looks like after I reload the UI.
Before reloading the UI I could reload all of the saved variables by doing:
Lua Code:
for k,v inpairs(JunkIt.AccountSavedVariables["PROFILES"]["PROFILE"])do
if v[1]== _sProfileName then
JunkIt.SavedVariables = v[2]
end
end
EDIT:
So I figured out the table is not adding an extra ["default"] level. Duh that is my default saved variables table. The problem is that everything else is disappearing when I reload the UI. Everything that has that (m) in front of it. I'm assuming that has something to do with metamethods & metatables, which I don't really understand very well. Does this have something to do with it?.
I found another post suggesting to use ZO_DeepTableCopy:
Lua Code:
local tSavedVars = ZO_DeepTableCopy(JunkIt.SavedVariables)
But ZO_DeepTableCopy doesn't copy metatables. That only copied the ["default"] table and GetInterfaceForCharacter() function. It did not copy the current settings, see picture below:
Is there an easier way to accomplish what I'm trying to do?
Where AddonSavedVarsName is the name you gave your saved variables in your Addon.txt file:
Lua Code:
## SavedVariables: JunkItSavedVars
ZO_DeepTableCopy does not copy metatables, but I was apparently copying the wrong table before. The table were copying now (in the above code) does not contain metatables so we can use ZO_DeepTableCopy. It can be used as: