i created a CCDictionary which has key is a String type and value is a CCInteger* type, but when i use writetofile method, it onl save the key, so i can’t use createWithContentsOfFile to load this file again, can you show me how to solve this problem? tks you!
here is my code:
dic = CCDictionary::create();
CCInteger* num = CCInteger::create(100);
dic->setObject(num,”first”);
num = CCInteger::create(200);
dic->setObject(num,”second”);
num = CCInteger::create(3000);
dic->setObject(num,”third”);
April 22nd, 2014 on 2:53 am
i created a CCDictionary which has key is a String type and value is a CCInteger* type, but when i use writetofile method, it onl save the key, so i can’t use createWithContentsOfFile to load this file again, can you show me how to solve this problem? tks you!
here is my code:
dic = CCDictionary::create();
CCInteger* num = CCInteger::create(100);
dic->setObject(num,”first”);
num = CCInteger::create(200);
dic->setObject(num,”second”);
num = CCInteger::create(3000);
dic->setObject(num,”third”);
dic->writeToFile(“demo.plist”);
it saved that:
first
second
third
April 22nd, 2014 on 2:55 am
first
second
third
April 23rd, 2014 on 12:17 pm
Hi Huy,
I think CCDictionary can only store CCString objects, as in my code. I mean, you can not use CCInteger or other type. Only CCString.
For more info, here in this post at the official forums:
http://www.cocos2d-x.org/forums/6/topics/49323?r=49342
I hope this helps.
April 23rd, 2014 on 12:22 pm
The mentioned above behavior only happens in Cocos2d-x below 3.0
Apparently in the new versions this issue has been fixed.
September 17th, 2014 on 4:36 am
Im using Xcode 5.1
cocos2d-x 2.1.5
I have an exact code like this, but it won’t generate .plist in resource folder
CCDictionary * m_game_data = new CCDictionary();
CCString userData =”2″;
m_game_data->setObject(&userData ,”current_level”);
m_game_data->writeToFile(“game_data.plist”);
September 17th, 2014 on 4:29 pm
I have exact code like this , but .plist couldn’t be locate anywhere in the project.
Im using Xcode 5.1
Cocos2d-x v2.1.5
September 17th, 2014 on 4:51 pm
Let me check your code and I will come back to you this evening, but that code should work.
At least in Windows, where I tested the original code.
October 20th, 2014 on 5:34 am
Do you have a version of this but using CCArray instead?
because CCarray uses item0, item1,item2, ..