KeyValues and Glon

Well I tried using keyvaluestotable like this



local stuff = util.TableToKeyValues({12, 13 14})
local stuff2 = util.KeyValuesToTable(stuff)


When I do



PrintTable(stuff2)


Works fine, shows things like
1 = 12
2 = 13
3 = 14
Which is what I want but when I do



print(stuff2[1])


It just prints nil

So then I tried Glon so I went about it the same way



local stuff = glon.encode({12, 13, 14})
local stuff2 = glon.decode(stuff)


which worked fine except when I used file.Write and file.Read I get a new error
Invalid number at 1! (“12”)

which is because it’s turned into a string now but this is how its done on the wiki so I don’t get it.

I think Glon is the way I need to go but there is another problem even if the above gets fixed, when encoding an entities table it seems glon does not like functions,
“Tried to write unwriteable type: function”

My short answer would be don’t use these methods. What’s the point of writting to file if it’s not even human readable? You should just use the sqlite library. Also you can’t store functions and I don’t know why you would want to. If you explain what you’re trying to do we can certainly find a solution though.

[editline]01:08AM[/editline]

Also : print(stuff2[“1”]) would probably work since when reading from a file everything is obviously a string.

Well this duplicator here needs a saving feature
http://www.facepunch.com/showthread.php?t=892064

So thats what I’m attempting to do.

I’m not trying to store functions but an entities table has an undo function in it among maybe a few others.

yeah you were right about the string index.

Ah then of course you’ll need text files, as for glon I would expect it to be able to decode what it encoded itself, but I have never used it.

About the entity tables, it is not possible to save it so that you can restore it later. It’s simply a reference for the most part. Most of the information in it would also be useless to you so you should concentrate on saving only things you can actually restore such as physical properties.

mhh, I was afraid I’d meet this road so now I’ll have to try and make a duplicator function. I was using duplicator.copy and paste, but I guess that needs to be removed now.

Well you could handle the copy pasting differently from the saving and loading. It’s just a matter of saving enough information that you’re able to recreate each entity exactly as it was.

Yes, I do think I did actually find a way. Thanks for keeping me on my same track ( =. Though I do still need Glon to work :confused: