A Question on Data Persistence

I’m about half way through my tutorial on saving and loading tables (http://codeatuts.blogspot.com.au/2012/09/tutorial-16-convert-string-to-table-and.html).

The wiki is helpful in explaining where all the various save and read data methods put their data and is worth a read (https://bitbucket.org/TwoLivesLeft/codea/wiki/com.twolivesleft.Codify).

Global data ends up in a Dictionary in the Codea preferences plist under the “CODEA_GLOBAL_DATA_STORE” key.

I want to be able to store level data (in a table) in the global data store and then load it from another App (the game which uses the level). This is easy enough once you have converted the table to a string.

My question is does anyone know a way to query the CODEA_GLOBAL_DATA_STORE Dictionary to get a list of keys? Ideally I need a “file manager” class which will return a list of existing keys. I suspect that this isn’t possible (from within Codea) otherwise it would have been done in the sample App Spritely.

The alternative is to try to come up with a way of saving each level to a unique key - I’m trying to avoid a user accidentally overwriting a level.

There is a listGlobalData() function, this will return the keys in the global store. Perhaps you could use that?

Outstanding - is this documented somewhere? It sounds perfect. I assume it returns the keys as a table?

Thanks @Simeon.

I just did a search for listGlobalData - It appears I am following in the tracks of the giants who have gone before me!

I found the JSON table to string converter quite useful to save parsed musical tune tables.

Thanks @Fred - my problem is that the table I’m trying to save is quite complicated, it is a two dimensional array containing a class which contains functions. The simple table serializers can’t handle this. Do you have a link to the JSON converter?

I think the issue is that the class implementation includes userdata. Can anyone confirm this? From what I have read this is the one data type you can’t serialize (or at least it appears very difficult).

It may be easier to redesign my data model.

With a bit more thought the answer is obvious…

I dont actually need to save the structure of the class as all I need are its contents. I will just write a function to extract the class data into a comma separated string and another one to read that data back in.

I will stop having a discussion with myself now.

Hi @Reefwing, the link to the JSON parser I used is: http://www.chipmunkav.com/downloads/Json.lua

But I don’t think it says you can use it on userdata…

Thanks @Fred

Hey Reefwing, this is slightly off topic but I’ve been reading your tutorials and they are really helpful. Thanks for bothering to share it forward. I know you’re learning stuff as you go which is helpful, but it takes that extra step to post it for those of us behind you.

Oh, and @Reefwing - sometimes the conversations with ones self are the most enlightening.

Hi @Heather - thanks for the kind words and glad the tutes are helpful. I wish I had more time to devote to them.

.@jlslate - LOL.