Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

UserDefault does not working [Ver 3.10][win32]

$
0
0

@lyvinhloi_cntt wrote:

This is my code

void GameScene::updateBoard()
{
	updateTopDown();
	updateLeftRight();
	if (!isPossibleMove())
	{
		log("Game Over");
		CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sounds/windows/game_over.wav");

		log("%d", (int)_gameScore);
		auto database = UserDefault::getInstance();
		database->setIntegerForKey("Score", (int)_gameScore);
		log("Save to database score = %d", database->getIntegerForKey("Score"));
		auto scene = EndScene::createScene();
		Director::getInstance()->replaceScene(TransitionPageTurn::create(0.2, scene, false));
	}
}

The Debug windows in VS shows me:


You can see that the 900 is the score which I logged by log("%d", (int)_gameScore);
After add this value the the UserDefault, and get it back, the value was 0 by this line
log("Save to database score = %d", database->getIntegerForKey("Score"));

I'm pretty sure that I only use UserDefault in this block of code, nowhere else. And you see that many thread exit, do they relative to this problem ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 2748

Trending Articles