saving/reading level data using plists

Member
Posts: 60
Joined: 2009.06
Post: #1
I have very simple data for each level.
stuff like some numbers, and the names of sprite files and backgrounds.
1)I'd like to read them off a plist file.
2)I'd also like to create the plist file separately from the code. Is there an editor?
How can I do the two things above?
Thanks! Smile
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #2
You can create and edit plists using the Property List Editor, which comes with the developer tools: /Developer/Applications/Utilities/Property List Editor

You can load your plist with something like this:

Code:
NSDictionary *myDictionary = [[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"MyLevel1Data" ofType:@"plist"]] retain];

... and presto, you have a dictionary of all your level data right there. Pretty simple huh?
Quote this message in a reply
Member
Posts: 60
Joined: 2009.06
Post: #3
Thanks AnotherJake!

Is there a way to add my own classes to the plist?
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #4
You mean, actual compilable code? Not really, no -- at least not in any practical sense.

Why? What did you have in mind?
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #5
NSCoding might serve your purpose, though making classes NSCoding compliant can be a bit tedious.

While I probably don't have the most efficient method of implementing Coder support, I know that mine actually works. Perhaps it (or something similar) will give you the inspiration to implement something that works well for you:

https://github.com/fsdev-cmiller/Outpost...Type.m#L37

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Moderator
Posts: 3,574
Joined: 2003.06
Post: #6
Ha! I totally mis-read aerospaceman's post!
Quote this message in a reply
Member
Posts: 60
Joined: 2009.06
Post: #7
thanks cmiller
I think I'll stick with a simple plist per Jake's suggestion. my level data is not very complex and i don't mind calling each basic variable separately.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Saving context markhula 4 6,081 Mar 8, 2011 02:37 AM
Last Post: markhula
  Level data structure tfifriday 3 3,132 Jan 9, 2009 02:30 PM
Last Post: ThemsAllTook