View Single Post
01/25/16, 02:49 PM   #9
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
Thumbs up

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:
  1. getFunc = function()
  2.     return SimpleXPBar.CurSV.textbar.color.r, SimpleXPBar.CurSV.textbar.color.b, SimpleXPBar.CurSV.textbar.color.g, SimpleXPBar.CurSV.textbar.color.a
  3. end,
  4. setFunc = function(r, g, b, a)
  5.     SimpleXPBar.CurSV.textbar.color.r = r
  6.     SimpleXPBar.CurSV.textbar.color.b = b
  7.     SimpleXPBar.CurSV.textbar.color.g = g
  8.     SimpleXPBar.CurSV.textbar.color.a = a
  9.     SimpleXPBar:UpdateControls()
  10. 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:
  1. color = {
  2.     r = 200,
  3.     g = 200,
  4.     b = 200,
  5.     a = 0.8,
  6. },

as for:
Originally Posted by coolmodi View Post
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 View Post
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:
  1. SimpleXPBar.accountwide_settings = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, { isAccountWide = false }, 'SimpleXPBar.AccountWide')
  2. SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings)
  3. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings)
  4.    
  5. if SimpleXPBar.accountwide_settings.isAccountWide then
  6.     ZO_DeepTableCopy(SimpleXPBar.AWSV, SimpleXPBar.CharSV)
  7.     SimpleXPBar.CurSV = SimpleXPBar.AWSV
  8. else
  9.     SimpleXPBar.CurSV = SimpleXPBar.CharSV
  10. 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:
  1. {
  2.     type = "checkbox",
  3.     name = "Use Account-Wide settings",
  4.     getFunc = function()
  5.         return SimpleXPBar.accountwide_settings.isAccountWide
  6.     end,
  7.     setFunc = function(val)
  8.         SimpleXPBar.accountwide_settings.isAccountWide = val
  9.                        
  10.         if val then
  11.             ZO_DeepTableCopy(SimpleXPBar.CharSV, SimpleXPBar.AWSV)
  12.             SimpleXPBar.CurSV = SimpleXPBar.AWSV
  13.         else
  14.             ZO_DeepTableCopy(SimpleXPBar.AWSV, SimpleXPBar.CharSV)
  15.             SimpleXPBar.CurSV = SimpleXPBar.CharSV
  16.         end
  17.     end,
  18. },
^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.

Last edited by Terrillyn : 01/25/16 at 02:57 PM.
  Reply With Quote