How to store dynamic objects/class objects/CCDictionary/CCArray in CCUserDefault::sharedUserDefault() for Android?

I am converting an IOS game to Android and in IOS we can just store arrays or dictionary objects.

And there’s none in CCUserDefault::sharedUserDefault()??

Am I suppose to store each single data one by one???

This will take forever :confused:

I hope somebody can help me.

:confused:

If you’re looking for replacement for array/dictionary in iOS, take a look at std::vector or std::map
Is that what you mean?

no, i mean for storing data in CCUserDefault::sharedUserDefault()

they only got 5 data type, int, float, bool, string and double. so how do i store CCObjects, CCArray or CCDictionary data or a dynamic object?

Does it mean, Cocos2d-x does support storing game saves for dynamic data? And only stores those 5 types of data?

Thanks.

Hope somebody can help me :confused:

You can write a CCDictionary to file? this makes a plist and you can load it back?

Hope it helps

1 Like

How do i do that??
Seppe R wrote:

You can write a CCDictionary to file? this makes a plist and you can load it back?
>
Hope it helps

yourdictionary->writeToFile(filepath) ?

CCDictionary* dict = CCDictionary::createWithContentsOfFile(filepath)

The same for CCArray

Hope it helps :slight_smile:

Oooh, that sucks :confused: the version im using doesnt have that function.

Do I have to update my cocos2d-x?

I think i tried before and it breaks my game :confused:

Anyway, thanks, I will look into that.

Seppe R wrote:

yourdictionary->writeToFile(filepath) ?
>
CCDictionary* dict = CCDictionary::createWithContentsOfFile(filepath)
>
The same for CCArray
>
Hope it helps :slight_smile:

maybe you can just copy the code from the new source :slight_smile:

Hmmm nope, it seems that it is only available for IOS and not Android :frowning: :frowning:

I wonder if there’s an alternative way to store a dictionary or an object.

Seppe R wrote:

maybe you can just copy the code from the new source :slight_smile:

Which version are u using? Because the version I use 2.1.4 works also on android =/

An alternetive way is to look for a json converter, and create json string from dictionary and store the json string in userdefaults, dont know if that is a good way though =/ but it could work.

Im using the old version. Anyway, I have added the new function into the old cocos2d-x im using.
And I got a new problem, I think it couldnt find the plist file to write it to.
I made an empty plist (Dictionary type) file through Xcode and put it in Resource folder for Android.

And I do something like this to write the dictionary to file

CCFileUtils::sharedFileUtils()->writeToFile(myDic, CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(“myDic.plist”));

But it fails to writetofile. Do you know what could cause the problem? I put the plist file in my Resource root folder with my other asset files/folders.

Can it generate a new plist file or i have to create it first?
Hope you can help me.

Thanks.

FaRHaN
Seppe R wrote:

Which version are u using? Because the version I use 2.1.4 works also on android =/
>
An alternetive way is to look for a json converter, and create json string from dictionary and store the json string in userdefaults, dont know if that is a good way though =/ but it could work.
>
https://github.com/430Studio/cocos2d-x-jsonconverter/tree/master/cocos2d-x-jsonconverter

I think you need CCFileUtils::sharedFileUtils()->getWriteablePath() which for ios is the documents directory. and just give it a name, it doesnt need to exist

gr