Updating Game - how to store the saved progress?

Hey guys!

I’ve been asking myself what would be the best way to store user data (i.e. Levels passed etc.), so when updating the game, this won’t be erased.
I haven’t found out if there’s like a special folder that won’t be erased nor overwritten.

So what would you do?
Uploading the JSON/sqlite data with the unique DeviceID ( system.getInfo( “deviceID” ) ) and downloading it once there’s an internet connection and precheck which version is newer?

Or is there somehow a folder or special naming conventition?

Thanks for your help!
Chris [import]uid: 13097 topic_id: 17865 reply_id: 317865[/import]

If you save a file to the Documents directory, it will not be overwritten when the user updates the app.

The only time that items in that folder will be erased is if they uninstall the app completely.

You could upload them all to a server i guess, but that seems like more work than is neccessary :smiley: [import]uid: 69826 topic_id: 17865 reply_id: 68189[/import]

After searching around I found NSUserDefaults to be the thing I’m watching for - but no way how I could adress it using Corona.

Does somebody know more about this?

Ressource:
http://stackoverflow.com/questions/7844565/saving-game-progress-with-nsuserdefault-good-or-bad-idea

http://mobile.tutsplus.com/tutorials/iphone/nsuserdefaults_iphone-sdk/ [import]uid: 13097 topic_id: 17865 reply_id: 68191[/import]

nope no idea :smiley:

But i dont really see why you would need that to save level scores, when all you have to do is save them to a file or database in the documents directory. [import]uid: 69826 topic_id: 17865 reply_id: 68192[/import]

Ah so the DocumentsDirectory is save from updating the app?
Good to know :smiley:
Then I only need to make sure the files won’t get overwritten :wink:

Is there also some kind of experiationDate like with cookies?

Edit: Sure, but I wasn’t sure if that get’s deleted when the game gets updated. :slight_smile:
Always trying to learn the best way of doing stuff before running into troubles :wink: [import]uid: 13097 topic_id: 17865 reply_id: 68193[/import]

Hey, xxxfanta, if you plan on saving data to document directory, and if you’d be interested in already made code (rather than building it on your own), I recommend looking into ice library , which you can find here: http://developer.anscamobile.com/code/ice

It uses both JSON and Sqlite3. I find it super duper flexible and easy to use. I use it in a most basic manner (and I found myself awed by it), but I can also see it being used in a quite sophisticated manner by well versed developers.

Naomi [import]uid: 67217 topic_id: 17865 reply_id: 68197[/import]

Personally I just use JSON myself.

I store all app-specific variables in a lua table. When I save the table I just use json.encode to serialize the table to a string, which is saved. When reading back the string json.decode converts it back to a table. Really simple to use… [import]uid: 70847 topic_id: 17865 reply_id: 68217[/import]

json.encode, very handy thanks for pointing that out… man i have got to read mor of the api guide… lol [import]uid: 11860 topic_id: 17865 reply_id: 68254[/import]

@Naomi:
Thanks, I’ve actually stumbled across this script some days ago and saw your posts about it :wink:
Though I’ve written my own little helper functions for saving data, I think I might give it a try, since it seems a bit more robust :slight_smile:

@swipeware
Yep, the storing wasn’t the problem - only the location so it won’t be deleted when updating the app! I’m aware of the simplicity of JSON and the use of sqlite :slight_smile:

Thanks for the quick help! :slight_smile: [import]uid: 13097 topic_id: 17865 reply_id: 68305[/import]

Hey, xxxfanta, here’s some fancy things you can do with ice that you may find interesting:

http://developer.anscamobile.com/forum/2011/10/19/savingloadind-data-easier-way#comment-67334

Cheers,
Naomi

[import]uid: 67217 topic_id: 17865 reply_id: 68423[/import]

So the next question is (I actually just posted about this exact question lol): How do you create a database in the document directory and check if its already there? [import]uid: 54716 topic_id: 17865 reply_id: 68445[/import]

Hey, ir8primates, I’m not sure what kind of database you’re trying to build, and I’m no database expert, so I don’t know what to tell you.

That said, with ice , it’s pretty easy to save data, and if/when you try and retrieve a data that does not exist, it will simply return nil. It’s totally nifty that way. I love the way it makes it so simple.

If you have a set of data that you want to initialize & save, I think ice can easily store the set of data for you. It’s a bit of a read, but if you are newbie like me, wading through the thread under ice library may simply answer lots of your questions and lead you to a solution you might be seeking: http://developer.anscamobile.com/code/ice

Naomi [import]uid: 67217 topic_id: 17865 reply_id: 68450[/import]

1r8primates, in my best ob1 voice I’ve got the code your looking for.

I have code to check this info and create a sqlite. DB etc… I was gonna work on a common lib and post it just have not.had the time. Ill post it when I get home tonight. [import]uid: 11860 topic_id: 17865 reply_id: 68454[/import]

Here is the code as promised.
this is what I use to check it any file exists.

[code]
myDocumentFileAndPath = system.pathForFile(“FileName.db”, system.DocumentsDirectory) --Write Access folder
myResourceFileAndPath = system.pathForFile(“FileName.db”, system.ResourceDirectory) --Protected Folder - Read only access


– CHECK TO SEE IF THE DB EXISTS, IF NOT THEN CREATE IT –

if doesDBFileExists(myDocumentFileAndPath) == false then
–open / create a new empty db file
end

if doesDBFileExists(myResourceFileAndPath) == false then
–open / create a new empty db file
end


– Check if DB File exists
– Returns true if it exists

function doesDBFileExists(sFileAndPath)

local bResults = false

if _G.debug then
print(" doesDBFileExists ->> the file path ->> " … sFileAndPath )
end

– io.open opens a file at filePath. returns nil if no file found
local file = io.open( sFileAndPath, “r” )

if file then – YES FILE OPENed -->
io.close( file )
bResults = true
else – FILE - NOT - OPENed -->
bResults = false
end

if _G.debug then
if bResults then
print (“doesDBFileExists ->> true”)
else
print (“doesDBFileExists ->> false”)
end
end

return bResults
end
[/code] [import]uid: 11860 topic_id: 17865 reply_id: 68491[/import]