If working with ZO_DeepTableCopy, the resulting table is not referenced by the saved variable. => not serialized to disk.
The questions are:
1. What is the expected behavior if you switch from char to account? Current settings taken over? Or switching to account settings?
2. What is the expected behavior if you switch from account to char? Current settings taken over? Or switching to char settings what ever they were?
I would try this (untested
):
At addon load (EVENT_ADDON_LOADED):
Lua Code:
SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings)
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
if SimpleXPBar.AWSV.general.account_wide then
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
If account settings are new, defaults are used. Then, if char is new, account settings are taken as default. (Which are default, if account settings were new)
Checkbox:
Lua Code:
setFunc = function(val)
if val then
-- purge data, due to different version
ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "2", nil, nil)
-- purge again, back to old version, take over char settings
SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, SimpleXPBar.CharSV)
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
-- purge data, due to different version
ZO_SavedVars:New("SimpleXPBar_Settings", "2", nil, nil)
-- purge again, back to old version, take over account settings
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
SimpleXPBar.AWSV.general.account_wide = val
SimpleXPBar:UpdateStats()
SimpleXPBar:UpdateValues()
end,
Alternative, you could access the saved variable more directly.