Apparently the issue was unrelated to ZO_DeepTableCopy, I must not have been paying attention when I wrote the colorpicker tables heres what the problem was:
Lua Code:
getFunc = function()
return SimpleXPBar.CurSV.textbar.color.r, SimpleXPBar.CurSV.textbar.color.b, SimpleXPBar.CurSV.textbar.color.g, SimpleXPBar.CurSV.textbar.color.a
end,
setFunc = function(r, g, b, a)
SimpleXPBar.CurSV.textbar.color.r = r
SimpleXPBar.CurSV.textbar.color.b = b
SimpleXPBar.CurSV.textbar.color.g = g
SimpleXPBar.CurSV.textbar.color.a = a
SimpleXPBar:UpdateControls()
end,
getFunc was returning rbga when it should have returned rgba
I still can't get
unpack to work though, it just returns white (or probably nil), does my color table have to look a certain way?
Lua Code:
color = {
r = 200,
g = 200,
b = 200,
a = 0.8,
},
as for:
Originally Posted by coolmodi
There's also something called metatables that can change the behavior of tables, ZO_DeepTableCopy ignores them, maybe that messes something up.
|
Originally Posted by sirinsidiator
I am not sure if ZO_DeepTableCopy is enough to replace the values correctly.
|
ZO_DeepTableCopy seems to be working fine on these SavedVars. I checked the tables in
DeveloperSuite they don't show any metatables, but this may be a limit of the tool.
And heres what is working for an account-wide toggle if anyone wants to know:
Lua Code:
SimpleXPBar.accountwide_settings = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, { isAccountWide = false }, 'SimpleXPBar.AccountWide')
SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings)
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings)
if SimpleXPBar.accountwide_settings.isAccountWide then
ZO_DeepTableCopy(SimpleXPBar.AWSV, SimpleXPBar.CharSV)
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
^this is called at AddonLoad (actually the first PLAYER_ACTIVATED event), it loads all the savedvars (accountwide setting, accountwide vars, character vars) and overwrites the character vars if accountwide is enabled ( so that our settings will be maintained on this character if accountwide is disabled on another ), then chooses to use CharSV or AWSV.
checkbox:
Lua Code:
{
type = "checkbox",
name = "Use Account-Wide settings",
getFunc = function()
return SimpleXPBar.accountwide_settings.isAccountWide
end,
setFunc = function(val)
SimpleXPBar.accountwide_settings.isAccountWide = val
if val then
ZO_DeepTableCopy(SimpleXPBar.CharSV, SimpleXPBar.AWSV)
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
ZO_DeepTableCopy(SimpleXPBar.AWSV, SimpleXPBar.CharSV)
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
end,
},
^when the user changes the checkbox, we decide to push our character vars to the accountwide vars (so our other characters can get them onload), or push our account wide vars to the character vars (so the player doesn't lose the changes they may have just made).
I'm still going to see if I can get rid of
SimpleXPBar.accountwide_settings because it seems redundant, (I was having problems getting settings to stick before using only two SavedVars).
Thanks for the info and suggestions posted coolmodi, sirinsidiator, they'll definitely help.