View Single Post
05/15/14, 09:02 AM   #6
Edda
 
Edda's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 60
Originally Posted by Garkin View Post
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.
Hmm ok. I dont remember if the 'version' key is at the same level as namespaces (when using namespace), but I think it is (hence you shouldn't be needing to 'skip' this key). Will check it this evening.

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 !

It sucks because I liked the idea of namespaces

*** EDIT ***

rawget(table, key) : I really don't see the point : example plz

Last edited by Edda : 05/15/14 at 09:09 AM.
  Reply With Quote