How do I make a variable that doesnt reset when I run the whole game?

in my game i want to make a currency for buying abilities and skins which you collect in the game. but i cant seem to find a way to save the amount of money i earned in the previous run since every time i run the scene it resets to zero.

Easy Cocos2dx, Has a cleaver little class thats just for that. and its called. UserDefault Class
you can store all sorts of stuff in it and then call it from anywhere in cocos like magic without haveing to worry about how to get data back, Love this class.

//Past code below give it a try.
UserDefault* def = UserDefault::getInstance();
def->setBoolForKey(“alive”,false);
def->setIntegerForKey(“Score”,0);
def->getIntegerForKey(“Score”);

//android studio will show you rest of sortage functions

thanks for the reply!!! will try

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

it worked thanks so much!!!