View Single Post
01/27/16, 03:31 PM   #26
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
Originally Posted by merlight View Post
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 View Post
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 View Post
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 View Post
Other than that, you should've focused on the color picker:
Lua Code:
  1. getFunc = function()
  2.         return SimpleXPBar.CurSV.textbar.color.r,
  3.  SimpleXPBar.CurSV.textbar.color.b--[[!!!]],
  4.  SimpleXPBar.CurSV.textbar.color.g--[[!!!]],
  5.  SimpleXPBar.CurSV.textbar.color.a
  6.     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:
  1. function SXPB_DeepCopy(src, def, dst)
  2.     dst = dst or {}
  3.     for k,v in pairs(def) do
  4.         if type(v) == "table" then
  5.             dst[k] = {}
  6.             SXPB_DeepCopy(src[k], def[k], dst[k])
  7.         else
  8.             dst[k] = rawget(src, k)
  9.         end
  10.     end
  11.     return dst
  12. end
  13.  
  14. SimpleXPBar.sample_table = {}
  15. 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:
  1. SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings, nil, nil, '$' .. SimpleXPBar.name)
  2. 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:
  1. SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SimpleXPBar.default_settings, nil, nil, '$' .. SimpleXPBar.name)
  2. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SimpleXPBar.default_settings)
  3.  
  4. if SimpleXPBar.AWSV.general.account_wide then
  5.     SimpleXPBar.CurSV = SimpleXPBar.AWSV
  6.     SimpleXPBar.CharSV.version = nil
  7.     SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SXPB_DeepCopy(SimpleXPBar.AWSV, SimpleXPBar.default_settings))
  8. else
  9.     SimpleXPBar.CurSV = SimpleXPBar.CharSV
  10. end
and
Lua Code:
  1. setFunc = function(val)
  2.     if val then
  3.         --load
  4.         SimpleXPBar.AWSV.version = nil
  5.         SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", 1, nil, SXPB_DeepCopy(SimpleXPBar.CharSV, SimpleXPBar.default_settings))
  6.         SimpleXPBar.CurSV = SimpleXPBar.AWSV
  7.     else
  8.         SimpleXPBar.CharSV.version = nil
  9.         SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", 1, nil, SXPB_DeepCopy(SimpleXPBar.AWSV, SimpleXPBar.default_settings))
  10.         SimpleXPBar.CurSV = SimpleXPBar.CharSV
  11.     end
  12.     SimpleXPBar.AWSV.general.account_wide = val
  13.     SimpleXPBar:UpdateStats()
  14.     SimpleXPBar:UpdateValues()
  15. end,

yay!

Last edited by Terrillyn : 01/27/16 at 03:43 PM.
  Reply With Quote