2013-07-06 2 views
0

그래서 나는 C++에서 글로벌 부울 변수를 사용하려고 시도하지만 항상 false를 반환합니다. 내 mainmenuscene.h 파일의 값을 정의Global Boolean이 항상 false로 나타나는 이유는 무엇입니까?

내 mainmenuscene.cpp 파일에서
#ifndef MAINMENUSCENE_H_ 
#define MAINMENUSCENE_H_ 
#include "cocos2d.h" 

extern bool boo_startgame; 


class MainMenu : public cocos2d::CCLayer 
{....} 

, 나는 true로 설정합니다

void MainMenu::menuStartSinglePlayer(CCObject* pSender) 
{ 
    boo_startgame=true; 
    CCDirector *pDirector = CCDirector::sharedDirector(); 
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); 

    // create a scene. it's an autorelease object 
    CCScene *pScene = HelloWorld::scene(); 

    // run 
    pDirector->pushScene(pScene); 
} 

하지만 내 helloworldscene.cpp 파일

, 그것은 다시 설정되어 그릇된.

#include "HelloWorldScene.h" 
bool boo_startgame; 

bool HelloWorld::init() 
     { 
       CCLog(boo_startgame ? "boo_startgame=true" : "boo_startgame=false"); 
       if (boo_startgame==true) 
        { 
        int_dealer=(arc4random() % 4); 
        } 
    ....} 

if 문 안쪽 부분은 결코 실행되지 않으므로 내 CCLog 코드가 엉망이 아닙니다. 무슨 일 이니?

+2

'menuStartSinglePlayer'가'init' 전에 어떻게 호출되는지 어떻게 알 수 있습니까? [최소 테스트 케이스] (http://sscce.org)를 만들 수 있습니까? –

+0

'helloworldscene.cpp'에'mainmenuscene.h '를 포함하지 않았습니다. 그것이 같은지 누가 알겠습니까? – chris

+0

@chris : 꼭 필요한 것은 아니지만 (일반적으로 좋은 아이디어 임) –

답변

-1

하나의 실행 스레드에서 수정할 수 있고 다른 스레드에서 테스트 할 수있는 경우 부울을 volatile bool boo_startgame으로 선언 할 수 있습니다.

관련 문제