View Single Post
01/26/16, 01:07 AM   #15
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 578
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:
  1. SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings)
  2. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
  3.      
  4. if SimpleXPBar.AWSV.general.account_wide then
  5.     SimpleXPBar.CurSV = SimpleXPBar.AWSV
  6. else
  7.     SimpleXPBar.CurSV = SimpleXPBar.CharSV
  8. 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:
  1. setFunc = function(val)
  2.     if val then
  3.         -- purge data, due to different version
  4.         ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "2", nil, nil)
  5.         -- purge again, back to old version, take over char settings
  6.         SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, SimpleXPBar.CharSV)
  7.         SimpleXPBar.CurSV = SimpleXPBar.AWSV
  8.     else
  9.         -- purge data, due to different version
  10.         ZO_SavedVars:New("SimpleXPBar_Settings", "2", nil, nil)
  11.         -- purge again, back to old version, take over account settings
  12.         SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
  13.         SimpleXPBar.CurSV = SimpleXPBar.CharSV
  14.     end
  15.     SimpleXPBar.AWSV.general.account_wide = val
  16.     SimpleXPBar:UpdateStats()
  17.     SimpleXPBar:UpdateValues()
  18. end,
Alternative, you could access the saved variable more directly.
  Reply With Quote