Saved var size always 0
Hi,
Facing a strange issue here but first the code : Lua Code:
RJ.Memory size is always 0 even tho I add stuff to it. And the savedVars file correctly displays saved data, and everything is working correctly but not the var size check. What I am trying to do is to display the RJ.Memory content (if size > 0) but it seems RJ.Memory is hooked to the top of the the saved var tree rather than the "Memory" namespace (notice I used a "Memory" namespace because I use another "Options" namespace in my saved vars). Full code can be found here : http://www.esoui.com/downloads/info4...emberJunk.html What I am obviously trying to loop thru the "Memory" table. |
#table only works for consecutively assigned numerical indexes, so t = {"a", "b", "c"} or t={[1] = "a", [2] = "b", [3] = "c"}
As you're using itemIds as the index, you're ending up with nonconsecutive elements. Use pairs(t) to iterate through and count elements Code:
local count = 0 |
Quote:
Will try this and see how it works. Thanks ! |
SavedVariables are bit tricky. It is not a simple table, it uses metatable and some default values.
In your case there will be always added key "version", so you have to be sure that you exclude this key from your count. By the way if you want to get just values that are really present in table and not values returned from metatable use rawget(table, key). EDIT: If you want to make it simple, add subtable to your saved variables. Do not store items as RJ.Memory[itemData.itemId], but use something like RJ.Memory.data[itemData.itemId]. It will save you lots of troubles. |
I had similar problem some time ago. I guess, you are initializing your addon from XML?
|
Quote:
About my way of creating the saved variable : RJ.Memory["foo"] = "bar" works fine (creates key/value in saved variable) RJ.Memory["foo"] = nil works fine (deletes key/value in saved variables) Things only screw when I do i.e. for k, v in RJ.Memory do d(k .. " : " .. v) end Suddenly it seems I am not handling with the same variable anymore ! :confused: It sucks because I liked the idea of namespaces :( *** EDIT *** rawget(table, key) : I really don't see the point : example plz :D |
Quote:
In your code above is missing pairs: Lua Code:
|
Quote:
Point is : Lua Code:
Doesn't return RJ.Memory pairs. Will retest it this evening. |
When is this function running? Calling d() too soon after a reloadui won't do anything as the chat windows aren't initialized
|
Quote:
http://www.youtube.com/watch?v=CYxMfVy5W00 http://nova-fusion.com/2011/06/30/lu...bles-tutorial/ EDIT (example): Lets set simple empty table called "t" with metatable "mt": lua Code:
lua Code:
Key "a" is not present in table "t", but because we have defined metamethod __index in metatable, you will get value from "defaults" table. If you try: lua Code:
|
Quote:
|
Quote:
|
Hmm. The only thing I can think of without being able to get into the game and look into it myself would be using your memory table as its own default table. That's a wild guess though.
|
Quote:
Another example. Instancing Addon.Options with Addon.Options as default value gives all the default values stored in Addon.Options to... itself (so Addon.Options == Addon.Options default value given no data is found locally - and option default values are written locally). If data is found locally then Addon.Options gets rewritten with local values. Saves you the hassle from read/write functions to user's saved variable i.e. if user changes an option then the addon bears with it AND it's saved locally. You know what I mean :D |
@Garkin
I was wrong :(
'Version' value is popped in every single namespace... |
Quote:
Code:
--Generate default CCD, then try to load saved Container from disk In fact the only times I use PER_GL_CCD at all is the get/set the String Index "CCD". Quote:
Note the bug with swallowed .lua parsing errors however (as long as it is not fixed). |
All times are GMT -6. The time now is 12:08 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI