on Dictionaries and pLists

Hi,

I am writing a crossplatform application in javascript using cocos2d-html5 , and i am using cocos2d-x for deploying it on android. (and cocos2d-iphone for iOS).

I need for the application a function that reads a plist file ands get a dictionary out of it (hence an associative array in javascript).
The thing is, if i try to use the method already written in javascript for that, it gets mapped and the correspondent method in the objective c (or c++) is missing. I managed to create and map a new working function i created in cc.fileUtils to iOS (in objective c) but i am having issues for the android (c++) version. The ccdictionary_to_jsval method in ScriptingCore.cpp fails to convert the dictionary and makes the application crash. I debugged the CCDictionary i create from the file using the functions already present in the library and seems ok, so i really don´t know where the problem might be.
I REALLY want to avoid write a custom DOM parser in javascript just because of that.
Is it possible to add this function for the next release of cocos2d-x? Or do you guys see a different and better solution? Has anyone tried to do that ?

Tyrion

I’m not sure exactly about your usage, but I have a similar issue with mapping JS associative array to native CCDictionary mentioned here: http://www.cocos2d-x.org/boards/20/topics/22698?r=23869#message-23869 (however unfortunately no solution yet, sorry!).

Thank you for the feedback anyway ! :slight_smile:

Hi!

How do you load your plist from js? I tried:

var actions = cc.DictMaker(); actions.dictionaryWithContentsOfFile(myPlist);

which works fine with cocos2d-html5, but in cocos2d-x, I have the error “cc.DictMaker is not a constructor”
Same problem occurs on cocos2d-iphone (I had to make my own bindings to a native function on IOS…).

Philippe Bobis wrote:

Hi!
>
How do you load your plist from js? I tried:
>
var actions = cc.DictMaker(); actions.dictionaryWithContentsOfFile(myPlist);
>
which works fine with cocos2d-html5, but in cocos2d-x, I have the error “cc.DictMaker is not a constructor”
Same problem occurs on cocos2d-iphone (I had to make my own bindings to a native function on IOS…).

fixed?

No, I give up with js for now.

JSB now supports to parse plist file now.
Please refer to PR https://github.com/cocos2d/cocos2d-x/pull/3236
The API is cc.FileUtils.getInstance().createDictionaryWithContentsOfFile(plist_filename);
Cocos2d-HTML5 will also support this API soon.
Thanks.

For me it works. Thanks James!