03/02/14, 07:15 AM | #1 |
Problem Traversing the Saved Variables Table
Okay,
I have set up my Saved Variables table as follows: Lua Code:
It then gets written to as follows: Lua Code:
But when I try and traverse the table as follows: Lua Code:
It seems to think it has the following data in there: GetInterfaceForCharacter : function : xxxxxxxx : (function) default : table : xxxxxxxx : (table) and despite having a table in there it doesn't traverse it further as expected, to see what else is hiding there. Is there a special way to traverse the Saved Variables table in ESO ? |
|
03/02/14, 01:50 PM | #2 |
I have written down that the first parameter passed to your function should be a string. So... "addonSV"
|
|
03/02/14, 02:29 PM | #3 | |
|
When your saved variables gets created it isn't blank. It stores the default values in a default table and GetInterfaceForCharacter is just a function there is in there. The default table is the same as SVDefault value, not sure what GetInterfaceForCharacter does, but it is in there all the same. I suggest using Zgoo to examine your saved variables. You can see exactly how it is laid out and see how it reacts when you change values in it. |
|
03/02/14, 02:31 PM | #4 |
That's the name of my addon saved variable table.
I've been putting this at the top of my addons, to make things a bit easier: local addonName = "XrysGatherer" local addonVersion = "0.0.1" local addonSV = addonName.."_SavedVariables" In the gather addon it works out as "XrysGatherer_SavedVariables". That's why I don't get, writing to it works fine .. but reading from it seems to be a bit messed up unless you are looking for a specific element like I do to identify an existing element. |
|
03/02/14, 02:47 PM | #5 | |
I guess it's confusing me why SVData is linked to the Data part of the table for writing but not for reading. The data is stored in the file as follows: ["Default"] ["@ACCOUNT"] ["$AccountWide"] ["Data"] ... data added by addon such as .. ["Khenarthi's Roost"] ["Aspect Rune"] [1] xPos = ... yPos = ... zone = ... etc when I use for index,value in pairs(SVData) do CHAT_SYSTEM:AddMessage(index,value,type(value)) end I am expecting the first element to be "Khenarthi's Roost", xxxxxx, table telling me to traverse down a level to receive the second as "Aspect Rune",xxxxx,table, with the third as "1",xxxx,table, and the fourth displaying the first set of actual values. However, if I say want to look for a specific item such as : local zoneData = SVData["Khanarthi's Roost"] local itemData = zoneData["Aspect Rune"] CHAT_SYSTEM:AddMessage(itemData[1].xPos,itemData[1].yPos) would display fine ( formatting aside that is ) |
||
03/02/14, 03:06 PM | #6 |
Looking at Esoheads Saved Variable table it looks like they do things differently so will try and do something similar with my addons.
Edit: Well after a lot of trial and error I finally almost had to copy what Esohead did and then adjust it to reflect my table contents. Ended up changing the layout of the Saved Variables File and spec Lua Code:
And using the way Esohead traversed through the table as a guide the following works flawlessly. Lua Code:
Last edited by Xrystal : 03/02/14 at 04:12 PM. |
|
03/02/14, 04:36 PM | #7 |
Okay, scratch the last reply.
It only works that way if I log in with an EMPTY!!!! Saved Variables table. Which totally defeats the point. If I log in with an empty table that games session will correctly traverse the table ( maybe without the need for adding the history header table but I am not spending another half hour changing it back now ) but the moment I tell it not to clear the table out the old traverse problem returns. By the way, what the heck is that version value for ? Should I set that to another value ? Can some bright spark see what the heck I am doing wrong here or is it a bug in the SavedVariables table? edit: As you can see this is annoying me to no end as I have wasted my beta weekend writing this addon and haven't been able to finish it because of this problem. Here is my code in its entirety barring the Update routine being called from the XML as per the norm. Lua Code:
Here is a screenshot of what is happening when I try and traverse through the table. If I change the traversing to the following in the hopes of bypassing the other stuff I get the same problem: Lua Code:
Again, only if the data exists when logging in. Last edited by Xrystal : 03/02/14 at 04:51 PM. |
|
03/02/14, 05:36 PM | #8 |
Hmm, very weird. ..
Thought it was zgoo bugging out as I am starting the addon with what I thought was an empty table but lo and behold I must be clearing it before it is loaded. However, because I thought it was clearing it the traversing of the table working is only listing the items gathered that session. Not the whole contents of the SavedVariables table. How do I access the history part of the table and traverse it ? SVData["History"] doesn't seem to work except for the fresh data that session. Guess it's time to tear apart zgoo but at 11pm UK time I probably won't get time to do anything useful if I get to grips with how they do it. Everything I have done so far that has taken me what seems to be all day but probably only half of it has been to no avail apart from stopping the error message from appearing. |
|
03/02/14, 07:37 PM | #9 |
Well 2 hrs or so later, finally got it figured... whew. Now I am happy and not the sulky bitch I was before rofl.
This is how I managed to access the saved variables in it's entirety. The local SVData file is only the contents of that session as it only works if you clear the tables when the addon is loaded, but the contents of XrysGatherer_SavedVariables is the whole data. This means I may be able to go back to the old version and use this code anyway and not have to fix the data everyone has been gathered so far. Unfortunately at 1:30am I doubt I'll be doing anything else this beta weekend except to test that the original version can traverse properly this way too and when I want to rather than only after it has been updated which is what it is currently doing and upload a working version of that. Lua Code:
|
|
05/26/14, 06:33 AM | #10 |
Yes I know I'm resurrecting an old thread, but its my own thread and I have resolved the problem I had before ... will mean a data reshuffle in my gatherer addon but I will tie that in with the database site going live.
I finally realised that the secret is to have a multiple level of data in the SVData table. Lua Code:
Lua Code:
|
|
05/26/14, 10:46 AM | #11 | |
Join Date: Apr 2014
Posts: 16
|
the real problem traversing the SavedVars is that the actual data is stored in a metatable.
i use the following (rather long) snipped to auto generate default get/set functions for my SavedVars. Lua Code:
Last edited by Aicam : 05/26/14 at 11:12 AM. Reason: variable renaming in code snippet |
|
05/26/14, 11:49 AM | #12 |
Currently I do the following, and then use the resulting tables for the traversing, its not perfect but for the most part it is called when people first open the history or import file and when they click the refresh button. Finding out that a slight change in data layout will bypass this problem will hopefully cut down on the amount of code I am needing to use. Technically accountWide also includes the characterWide values as well but it makes it clearer that I am only looking at accountWide values.
Lua Code:
|
|
05/28/14, 10:27 AM | #13 |
|
As I wrote in my update of the Wiki entry on saved variables, # does not work on the SavedVariable access object - it always will return 0, regardless how many int indexed values you have in there.
It does work fully on table you put one level "deeper". The easiest trick is to just add string index and store your table under that string index. |
05/28/14, 01:13 PM | #14 |
|
# should work on saved variables if you construct it like an array. If this isn't the case, it won't work. # only works for proper arrays.
|
05/28/14, 02:30 PM | #15 | |
|
Sub-elements of the saved table work normaly regarding # Just put it into SavedVar.Data[i] isntead of SavedVar[i] and you can properly itterate over SavedVar.Data using #SavedVar.Data. It is also better practice to hand normal arrays (instead of Saved Var Acessor objects) to functions. |
|
05/28/14, 09:02 PM | #16 | |
|
|
|
ESOUI » Developer Discussions » Lua/XML Help » Problem Traversing the Saved Variables Table |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|