Data Persistance
by Jason Darby · in iTorque 2D · 11/02/2009 (6:44 pm) · 17 replies
Hello
On the final part of Project X1 :) and the last thing to do is data persistance. We have a highscore table, which stores data for the lifetime of the application. Once the application is closed/phone switched off, the information is overwritten.
How do i save data to the phone for longer term access?
Jason
About the author
Computer games book author, have written 6 game creation books, published by Cengage Course Technology. Owner of Arcade website www.madword.com and Castle software.
#2
11/02/2009 (7:35 pm)
OpenFeint can also store offline highscores, so that's an alternative.
#3
saveGameDataToDevice()
LoadGameDataFromDevice()
11/03/2009 (3:09 am)
Use the functionality added to the 1.3 beta:saveGameDataToDevice()
LoadGameDataFromDevice()
#4
How are they different then fileObject?
11/03/2009 (12:47 pm)
Luke, what are these new functions?How are they different then fileObject?
#5
11/03/2009 (1:41 pm)
They save and load strings within the default preferences plist. You supply a string and a key, no worries about finding the right path to save to (or even a filename).
#6
I think it would be much better to be able to save XML data out to the app's /Documents/ directory. Flexibility and nice integration with Torque could be found that way.
*adds to ToDo list*
11/03/2009 (4:20 pm)
This setup is hardly ideal IMO. For anything complex it'll quickly fall short of what you'll need.I think it would be much better to be able to save XML data out to the app's /Documents/ directory. Flexibility and nice integration with Torque could be found that way.
*adds to ToDo list*
#7
11/04/2009 (3:50 am)
Craig, a high score table is hardly complex :)
#8
Although , there is already the XML classes in the engine, with a good example in the common folder for the commonconfig.xml if you really need a reference.
11/04/2009 (4:07 am)
And XML on a mobile device sounds like the slowest possible choice for data persistence. The operating system offers a registry for key value pairs, and it also offers entire API's like Core Data which are in essence streamlined dictionary types and what not. But i would say the saveGameData can do a lot for you already, if you are saving data for an app. If you are storing entire game assets its obvious you wont do it there but you dont want to be using a chainsaw for a pocket knife job.Although , there is already the XML classes in the engine, with a good example in the common folder for the commonconfig.xml if you really need a reference.
#9
Sure they are hardly complex if they are just a name and a score. Imagine if you had several users, different modes, different types of scores (points vs time for example) and extra info like where when they scored those... it quickly becomes troublesome (not impossible, just not worth the hassle imo) to store that information within the current 1.3 methods.
@Sven
I think you may be "over egging" the speed deficiencies of XML somewhat. Sure, keyed pairs are whizbang quick, but for how often you save out data and the amount of data too, XML is a perfectly valid for this application in my eyes. I consider it using a nice kitchin knife for a pocket knife job instead :) A bit overkill in some circumstances but overall a worthy choice.
11/04/2009 (6:54 am)
@LukeSure they are hardly complex if they are just a name and a score. Imagine if you had several users, different modes, different types of scores (points vs time for example) and extra info like where when they scored those... it quickly becomes troublesome (not impossible, just not worth the hassle imo) to store that information within the current 1.3 methods.
@Sven
I think you may be "over egging" the speed deficiencies of XML somewhat. Sure, keyed pairs are whizbang quick, but for how often you save out data and the amount of data too, XML is a perfectly valid for this application in my eyes. I consider it using a nice kitchin knife for a pocket knife job instead :) A bit overkill in some circumstances but overall a worthy choice.
#10
For those who don't use OpenFeint, perhaps there should be a set of functions to maintain a highscore list. Simply "set number of entries", "set type of entries" (high to low or low to high, time or score) "get all entries" and "submit entry". The latter returns true and ranking if your entry got a place.
11/04/2009 (8:18 am)
XML is not out of the question for this sort of thing, no. The OS already has nice functions for highscore tables.For those who don't use OpenFeint, perhaps there should be a set of functions to maintain a highscore list. Simply "set number of entries", "set type of entries" (high to low or low to high, time or score) "get all entries" and "submit entry". The latter returns true and ranking if your entry got a place.
#11
11/04/2009 (2:59 pm)
I'm getting the impression from Craig's posts that XML saving/loading is not currently working with iTGB 1.3 which really confuses me. I'm running 1.2 and creating an XML file to save my data using the standard XML examples I found on the site here and it seems to be working fine. Of course, I've only tested on the iTouch so far so it's possible that there's something about the iphone itself that's different but just using XML seems like the simplest solution for data persistence especially in the case where you don't have much data to store.
#12
Afaik it should work - sorry to have given the impression otherwise. I'm currently grappling with some bizarre pointer issues in that area of code (likely my own doing :D) so I can't confirm at the moment, but the code is there...
11/04/2009 (3:04 pm)
@NateAfaik it should work - sorry to have given the impression otherwise. I'm currently grappling with some bizarre pointer issues in that area of code (likely my own doing :D) so I can't confirm at the moment, but the code is there...
#13
Ah, I misread your post then. I was worried that there was some incompatibility that would mess up my save/lord function when I deployed to the iphone or upgraded to 1.3. Good luck on solving your bizarre pointer issues.
11/04/2009 (3:21 pm)
@CragAh, I misread your post then. I was worried that there was some incompatibility that would mess up my save/lord function when I deployed to the iphone or upgraded to 1.3. Good luck on solving your bizarre pointer issues.
#14
The beta 1.3 download has the filename of "T2D_iPhone_Beta_1_0.tgz.gz". Is this the correct file?
BTW, my iphone Tower Defense game is almost ready for beta!
Update: I found this in iPhoneFileio.mm. I didn't have *.mm setup in my search.
11/25/2009 (2:10 am)
I just downloaded the beta 1.3 version and I could not find the "saveGameDataToDevice()" and "LoadGameDataFromDevice()" methods when doing a source search. Is the latest beta available for download under the user accounts or am I just not searching for the correct strings?The beta 1.3 download has the filename of "T2D_iPhone_Beta_1_0.tgz.gz". Is this the correct file?
BTW, my iphone Tower Defense game is almost ready for beta!
Update: I found this in iPhoneFileio.mm. I didn't have *.mm setup in my search.
#15
11/25/2009 (3:13 am)
Sounds exciting darren! How about a forum post about the game :)
#16
11/25/2009 (1:38 pm)
Or even a blog+post in a showoff thread :)
#17
also, if I were to attempt to implement OpenFeint, would I have to know Objective-C? It would be new to me so would it be hard? Would the high scores be available to me in torquescript or just Objective-C?
Thanks
11/25/2009 (4:25 pm)
Hi. I was wondering if you could elaborate on saveGameDataToDevice() and LoadGameDataFromDevice(). Can I only save a sting of text? I need to be able to save an entire simset. Can I use that to do it? Also, how do I tell it what to load in afterward? Like if I have multiple things I want to save independently, after I save them, how do I load them in individually, or does it just load in all the saved items you have?also, if I were to attempt to implement OpenFeint, would I have to know Objective-C? It would be new to me so would it be hard? Would the high scores be available to me in torquescript or just Objective-C?
Thanks
Torque Owner Eyal Erez