Hi,
Hoping someone on here can help as I’ve been beating my head against this for a long time. At this point, it looks like a potential bug (as code from numerous other tutorials and posts doesn’t seem to work as well), but I’m still hopeful it’s something bone-headed I’m doing. I’ve seen some other recommendations for some xml packages to use to read plists, but I’d prefer to use the functionality of the Cocos2dx engine if I can get it to work.
I’m loading a plist file and trying to read some values from a dictionary from that file (and I’ve tried with combinations of arrays and dictionaries but always hit some flavor of the same issue). Reading values always returns NULL. The plist seems to load fine, as I can read all the keys in the file, but anytime I try to retrieve a value I get NULL.
The first two lines seem to work, but the third line, obj returns NULL.
CCArray* _levels = CCArray::createWithContentsOfFileThreadSafe("levels.plist");
CCDictionary* _chosenLevel = (CCDictionary*)_levels->objectAtIndex(0);
CCString* obj = (CCString*)_chosenLevel->objectForKey("start");
But, I can do this and see all the keys printed to the output window:
CCArray* keys = _chosenLevel->allKeys();
for (int i = 0; i < keys->count(); i++)
{
CCString* key = (CCString*)keys->objectAtIndex(i);
CCLog(key->getCString());
}
And, all of these return NULL:
string myString = _chosenLevel->valueForKey("start")->getCString();
CCObject* myObject = _chosenLevel->objectForKey("start");
CCDictElement* dictElement = (CCDictElement*)_chosenLevel->objectForKey(key->getCString());
_chosenLevel->valueForKey("end")->intValue();
I’ve also tried with CCFloat* and CCInteger* but still always get NULL back
Pretty much anything I’ve tried that tries to get either an objectForKey or a valueForKey always returns NULL.
The plist file is:
start
1
end
5
right
2
left
2
middle
13.5
Any ideas?
I’m using Cocos2dx 2.2, using C++, in Visual Studio, developing for an app for the Windows 8.1 environment. Everything else I’m doing is working fine.
Thanks in advance