Thread Tools Display Modes
01/26/16, 03:30 PM   #21
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
I tried what you said before votan, and its actually just corrupting the table, even a fresh one.

first we call
Lua Code:
  1. SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings, nil, nil, '$' .. SimpleXPBar.name)

and this is AWSV
Lua Code:
  1. {
  2.     __index = {
  3.         mysaveddata1,
  4.         mysavedata2,
  5.         version = "1",
  6.     },
  7.     __newindex = function,
  8.     default = table...,
  9.     GetINterfaceForCharacter = function,
  10. }

then we call
Lua Code:
  1. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)

and it does this to CharSV
Lua Code:
  1. {
  2.     __index = {
  3.         default = table...,
  4.         GetInterfaceForCharacter = function,
  5.         version = "1",
  6.     },
  7.     __newindex = function,
  8.     default = table...,
  9.     GetINterfaceForCharacter = function,
  10. }

Looks like the meta data is getting copied too.

if I try this instead
Lua Code:
  1. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV.__index)

then we get only
Lua Code:
  1. {
  2.     __index = {
  3.         version = "1",
  4.     },
  5.     __newindex = function,
  6.     GetINterfaceForCharacter = function,
  7. }

Basically I want the data between AWSV and the current CharSV to be synced when account_wide is enabled, and not synced when its not.
It doesn't have to be synced all the time, only when changing account_wide, basically what you where trying to do in post 15.

Last edited by Terrillyn : 01/26/16 at 06:10 PM.
  Reply With Quote
01/26/16, 04:17 PM   #22
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Terrillyn View Post
I tried what you said before voltan, and its actually just corrupting the table, even a fresh one.
I'm a bit suprised. Did you try that with a fresh/empty saved-variable?
I check that tommorrow.
And by the way my nickman is votan, not voltan. I have nothing to do with Flash Gordon
  Reply With Quote
01/26/16, 06:12 PM   #23
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
I'm a bit suprised. Did you try that with a fresh/empty saved-variable?
Yea, I deleted the savedvars file and then enabled the addon to check, its corrupting on the first-run.
If you'd like I can send you the current addon zip to test?

And by the way my nickman is votan, not voltan. I have nothing to do with Flash Gordon
Sorry about that, idk how I didn't catch that, must've miss-typed, fixing it now.

Last edited by Terrillyn : 01/26/16 at 06:17 PM.
  Reply With Quote
01/27/16, 01:25 AM   #24
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Ah, I see. The ZO_SavedVars is not the raw table of the saved variable and contains metadata.

Next try is to access the raw tables:
Code:
local esoAccount = SimpleXPBar_Settings["Default"][GetDisplayName()]
SimpleXPBar.esoAccount = esoAccount
SimpleXPBar.rawCharSV = esoAccount[GetUnitName("player")]
SimpleXPBar.rawAWSV = esoAccount["$AccountWide"]
These tables can be nil.
Lua Code:
  1. SimpleXPBar.esoAccount[GetUnitName("player")] = ZO_DeepTableCopy(SimpleXPBar.esoAccount["$AccountWide"] or {})
  2. -- Now we have a fresh copy to be used here:
  3. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, nil)
And of course the other way round.
Not as transparent to the internal structure, but...

Last edited by votan : 01/27/16 at 02:06 AM.
  Reply With Quote
01/27/16, 06:45 AM   #25
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Terrillyn View Post
I tried what you said before votan, and its actually just corrupting the table, even a fresh one.

first we call
Lua Code:
  1. SimpleXPBar.AWSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.default_settings, nil, nil, '$' .. SimpleXPBar.name)
Use :NewAccountWide. This is just obscuring the meaning.
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.

Originally Posted by Terrillyn View Post
and this is AWSV
Lua Code:
  1. {
  2.     __index = {
  3.         mysaveddata1,
  4.         mysavedata2,
  5.         version = "1",
  6.     },
  7.     __newindex = function,
  8.     default = table...,
  9.     GetINterfaceForCharacter = function,
  10. }
That looks like a metatable, not AWSV contents.

Originally Posted by Terrillyn View Post
then we call
Lua Code:
  1. SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
Defaults are magic. You never, ever, want to pass something you pulled from SV as defaults for another. Pass raw defaults table that's in addon source.


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. 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,
  Reply With Quote
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
01/28/16, 09:33 PM   #27
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
As merlight said ZO_DeeptableCopy doen't copy metatables. Just copy from/to _G instead of trying to copy SimpleXPBar.AWSV or SimpleXPBar.CharSV
and you don't need SimpleXPBar.accountwide_settings, you can use SimpleXPBar.AWSV

Warning: Spoiler
  Reply With Quote
01/29/16, 02:23 PM   #28
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
It doesn't seem like you read any of the posts here:
As merlight said ZO_DeeptableCopy doen't copy metatables. Just copy from/to _G instead of trying to copy SimpleXPBar.AWSV or SimpleXPBar.CharSV
and you don't need SimpleXPBar.accountwide_settings, you can use SimpleXPBar.AWSV
  • I didn't need to copy the metatable, I needed to copy through the metatable without effecting it, this is solved.
  • SimpleXPBar.accountwide_settings hasn't been used since I started this thread.
  • Also I just checked the settings in _G and they seem to be out-of-date as soon as you change a setting, possibly updated at a later time, which makes copying from them a non-option.

I appreciate any help I got, thank you all, but how do I mark this thread solved?

Last edited by Terrillyn : 01/29/16 at 02:25 PM.
  Reply With Quote
01/29/16, 04:52 PM   #29
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Change the thread's name to "[SOLVED]Having issues creating an account-wide settings toggle" maybe.

Edit:
Just tested it and you are only able to edit the title of your first post in your thread :-(
So just write a BIG GREEN "SOLVED" at your first thread's post start?

Last edited by Baertram : 01/29/16 at 04:55 PM.
  Reply With Quote
01/29/16, 10:13 PM   #30
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Terrillyn View Post
It doesn't seem like you read any of the posts here:
  • I didn't need to copy the metatable, I needed to copy through the metatable without effecting it, this is solved.
  • SimpleXPBar.accountwide_settings hasn't been used since I started this thread.
  • Also I just checked the settings in _G and they seem to be out-of-date as soon as you change a setting, possibly updated at a later time, which makes copying from them a non-option.

I appreciate any help I got, thank you all, but how do I mark this thread solved?
Your right I didn't read any of the posts, I didn't need to. I read the question (the original post), I knew how to do it, & I posted it.

From your post it appeared you wanted to create a toggle that swaps between character & account wide settings and you wanted to copy the current acccountwide saved vars to the character saved vars to sync them. If something else was added later or changed your right I missed it.

I understand you wanted to copy through the metatable. I just went around it, all of that metadata is stored in _G which is what I copied.

_G is up-to-date when you change settings, that code works.
I'm guessing you had zgoo open and you were checking your SimpleXPBar.CurSV table after the swap/copy which would show the settings were out of date because zgoo would still be referencing the old table from before the swap. You can't just open & close the saved var table, you have to close zgoo & re-run /zgoo xxx after the swap for it to show the updated settings.

I'm glad you got it to work though.
  Reply With Quote
01/30/16, 01:28 AM   #31
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
Originally Posted by circonian View Post
I'm guessing you had zgoo open and you were checking your SimpleXPBar.CurSV table after the swap/copy which would show the settings were out of date because zgoo would still be referencing the old table from before the swap. You can't just open & close the saved var table, you have to close zgoo & re-run /zgoo xxx after the swap for it to show the updated settings.

I'm glad you got it to work though.
I actually went into the settings panel changed a setting, then typed /explorer (from DevTools) (which should have been uptodate as I've seen in other tables), opened the <addonname>_Settings table and what it gave we was not up to date with what I changed, SimpleXPBar.CurSV was however. Doesn't the metatable get added to the table and not just wrap it?
The attached picture should tell why I think this, maybe I'm wrong though.
In the picture CurSV is AWSV which should have the same values as $AccountWide, but $AccountWide has outdated values if I change something.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_20160129_233313.png
Views:	494
Size:	14.3 KB
ID:	680  

Last edited by Terrillyn : 01/30/16 at 01:36 AM.
  Reply With Quote
01/30/16, 02:50 AM   #32
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Terrillyn View Post
I actually went into the settings panel changed a setting, then typed /explorer (from DevTools) (which should have been uptodate as I've seen in other tables), opened the <addonname>_Settings table and what it gave we was not up to date with what I changed, SimpleXPBar.CurSV was however. Doesn't the metatable get added to the table and not just wrap it?
The attached picture should tell why I think this, maybe I'm wrong though.
In the picture CurSV is AWSV which should have the same values as $AccountWide, but $AccountWide has outdated values if I change something.
Those are not supposed to be the same. Each table will have its own id. The only way those id's would be the same is if both values pointed to the same reference (same table). Those two tables having different values does not mean they don't contain the same data.

Lua Code:
  1. temp = { dummyValue = true }
  2. temp2 = temp
  3. d("Table 1: "..tostring(temp))
  4. d("Table 2: "..tostring(temp2))
  5. -- Those would have the same id because temp 2 points to temp 1
  6. -- They both reference the same table, temp 2 is NOT a copy
  7.  
  8. temp3 = ZO_DeepTableCopy(temp)
  9. -- Temp & temp3 would not have the same id
  10. -- they are two different tables, regardless of their content.

The picture you posted is comparing CurSV & _G["xxxxx"]["Default"][sDisplayName]["$AccountWide"]
Those are not the same tables, they shouldn't have the same ID's.

Last edited by circonian : 01/30/16 at 02:58 AM.
  Reply With Quote
01/30/16, 02:59 AM   #33
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Terrillyn View Post
Doesn't the metatable get added to the table and not just wrap it?
The attached picture should tell why I think this, maybe I'm wrong though.
In the picture CurSV is AWSV which should have the same values as $AccountWide, but $AccountWide has outdated values if I change something.
ZO_SavedVars is a wrapper, which wraps around the raw table to keep it clean for serialization.
That's why I suggested to use access the saved variable directly before wrapping in comment 24.
Take a look at CreateExposedInterface to see, that there are actually two more tables involved.
You should find the reference to your table within CurSV.
  Reply With Quote
01/30/16, 03:19 AM   #34
Terrillyn
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 24
Thank you for your patience, I get it now.

I also see were some of my confusion was coming from, there must be a bug with the DeveloperSuite*, as its giving old data until I actually access said data with the console, weird.
  Reply With Quote
01/30/16, 06:24 AM   #35
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Originally Posted by Terrillyn View Post
Thank you for your patience, I get it now.

I also see were some of my confusion was coming from, there must be a bug with the DeveloperSuite*, as its giving old data until I actually access said data with the console, weird.
I didn't thought about that before, too. So no need to excuse

I think DeveloperSuite does best possible for an addon. It is not a JIT debugger from vendor.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Having issues creating an account-wide settings toggle

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off