Originally Posted by merlight
Use :NewAccountWide. This is just obscuring the meaning.
|
I know, I did this at the time to see if it was something wrong with the character name.
Originally Posted by merlight
Also, SV version should be number. Not that it's very useful, but if you ever need to go beyond "9", be prepared for an unpleasant surprise.
|
This was definaetly a mistake, however if I change it now this will cause users pain, so I'll just keep it for now, and figure out how strings are compared so I can avoid any future problems.
Originally Posted by merlight
I'd solve the whole thing in a completely different way, but technically the only thing that's wrong with your original code is that ZO_DeepTableCopy copies metatables and you probably don't want that in this case, as it can mess with ZO_SavedVars magic. So you'll be better off writing your own RawDeepTableCopy.
|
Just figured out how to do this, I just wasn't understanding how access to metatables works, found out about rawget and finally got it working(further below).
Originally Posted by merlight
Other than that, you should've focused on the color picker:
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,
|
Already took care of this in a previous post.
----
Finally figured out how to make a copy of the SavedVars table without metadata
Lua Code:
function SXPB_DeepCopy(src, def, dst)
dst = dst or {}
for k,v in pairs(def) do
if type(v) == "table" then
dst[k] = {}
SXPB_DeepCopy(src[k], def[k], dst[k])
else
dst[k] = rawget(src, k)
end
end
return dst
end
SimpleXPBar.sample_table = {}
DeepMove(SimpleXPBar.AWSV, SimpleXPBar.default_settings, SimpleXPBar.sample_table)
I'm using the default_settings keys to keep everything consistent.
So I can call it like this
Lua Code:
SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings, nil, nil, '$' .. SimpleXPBar.name)
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, DeepMove(SimpleXPBar.AWSV, nil, SimpleXPBar.default_settings))
Then I looked up
ZO_SavedVars:New ->
CreateExposedInterface and apparently just setting the savevars version to nil will cause it to get nuked on the next load, and here we get:
Lua Code:
SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SimpleXPBar.default_settings, nil, nil, '$' .. SimpleXPBar.name)
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SimpleXPBar.default_settings)
if SimpleXPBar.AWSV.general.account_wide then
SimpleXPBar.CurSV = SimpleXPBar.AWSV
SimpleXPBar.CharSV.version = nil
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SXPB_DeepCopy(SimpleXPBar.AWSV, SimpleXPBar.default_settings))
else
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
and
Lua Code:
setFunc = function(val)
if val then
--load
SimpleXPBar.AWSV.version = nil
SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", 1, nil, SXPB_DeepCopy(SimpleXPBar.CharSV, SimpleXPBar.default_settings))
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
SimpleXPBar.CharSV.version = nil
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SXPB_DeepCopy(SimpleXPBar.AWSV, SimpleXPBar.default_settings))
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
SimpleXPBar.AWSV.general.account_wide = val
SimpleXPBar:UpdateStats()
SimpleXPBar:UpdateValues()
end,
yay!