Road to CocoStardom: .plist Root (Array vs Dictionary)

Cocos2dX V2.2.5

I’ve just learned about .plist today and that I can use it to store my game data. . I think I can even use it to save/load my game.

What I want to know is that in the “ROOT”, should I use the default Dictionary or the Array type?? Please tell me the difference. And also, when to use each of them :smile:

Thanks!

Use an array when you want a collection if identical items - for example you might want to store all of your ‘baddies’ information - and you might have one or fifty baddies - so use an array.

Use a Dictionary when you need to be able to access a particular item by name.

e.g. in your array of Baddy data, each element of the array would be a dictionary, each containing nodes such as “location”, “remainingHealth” etc.

As for the root - I always recommend using a dictionary for the root, even if there is only one entry, as I find it easier to try different settings like this - i.e. one element called “live” and another called “test” so I can change which one I want to run and when.

mhmm, thnx for the reply mate, appreciate. . as of now I find using Dictionaries as easier to use than Arrays. In lua, i can use arrays all day, here using C++ Cocos2dx, I’d spent a year and I’d still get nowhere, lol . .

by the way how do you get a string’s length?
i got

//access a string from plist
const char *pic1 = miniDict->valueForKey(“question”)->getCString();
CCLOG(“the string retrieved is %s”, pic1) ; // works fine, returns desired string from plist

int strlength;
strlength = pic->length(); // doesnt work lol

any alternatives?

nevermind , solved it

change “const char” to “const CCString” for you to be able to invoke ->length()

:smiley: