views:

36

answers:

4

I am off to making a tower defense game, and will have about 40-50 towers and about 20 enemies on screen. Those objects will have a few properties each, like hp, damage, speed etc.

What is the limit of the defaults db? I don't feel like writing SQL queries for simply saving the state of my game..

A: 

It might be easier with something like this to take the data and just read/write it to a file - rather than dealing with something like the defaults. You could basically have a static data structure that you convert to an NSData with - and write it to storage with NSFileManager's createFileAtPath:contents:attributes: in one whack!

Brad
Does this mean i could just take my whole NSMutableArray and save that as a file without complying with NSCoding, and then just read the file back into an NSMutableArray? Sounds a bit too good to be true..
Maciej Swic
No - you would have to implement NSCoding - or iterate through the array and dump each object.
Brad
+2  A: 

NSUserDefaults provides a way to store basic information. The only thing is the classes you intend to store must be NSCoding-compliant and wrapped in NSData. This is because NSUserDefaults requires its content to be 100% PLIST-compliant types (NSDictionary, NSArray, NSData, NSString, NSNumber, NSValue...).

Brad is correct, however: easiest (and best practice) to dump this in a data file.

Joshua Nozzi
Any tutorials for dumping this kind of data to files please? Would i only be able to dump the NSMutableArray or perhaps the whole cocos2d GameScene that i want to save the state of? That would be amazing.
Maciej Swic
Second verse same as the first: Learn about archives and serializations in Cocoa: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Archiving/
Joshua Nozzi
+2  A: 

Sure - you can use NSUserDefaults to store as much info as you want. You could also look into Core Data as well (might scale a lot better in the future).

AdamH
+2  A: 

Your best bet is to look into NSCoder methods for saving entire class/properties.

There are a dozen NSCoder tutorials you can check out:

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=nscoder+tutorial

Jordan