Hi, I'm having trouble create an 'account-wide settings' toggle for one of my addons, well actually I've got it working but its causing weird behavior with the colorpicker controls and some of the other controls, and I'm hoping someone can help me figure out what I'm doing wrong, here is some scippets of how I'm accomplishing the accountwide toggle:
When my addon loads here is how I load the settings:
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
and here is how my 'Account-Wide' toggle is setup (using libaddonmenu):
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 SimpleXPBar.accountwide_settings.isAccountWide then
ZO_DeepTableCopy(SimpleXPBar.AWSV, SimpleXPBar.CharSV)
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
ZO_DeepTableCopy(SimpleXPBar.CharSV, SimpleXPBar.AWSV)
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
end,
},
Just for reference here is how the Colorpicker is setup:
Lua Code:
{
type = "colorpicker",
name = "Color",
width = "full",
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,
},
I'm using
SimpleXPBar.CurSV to reference my settings through-out the rest of the code, and the issue I'm having with the colorpicker is that it keeps flipping back and forth between 2 different color settings everytime I click it, I have a feeling this has to do with how lua is referencing the object but I cant figure what its doing in this case. I've already searched around the forums and google trying to find some sample of how to create a accountwide toggle correctly but I ended up looking at how
Destinations and
MasterMerchant do it and trying something similar.
Any suggestions on a better way of implementing this or a fix would be appreciated.