Access variable from 1 layer to another

Hi,
I want to access a variable from 1 layer to another.
I tried implementing few things but all failed.

I used CC_SYNTHESIZE(int, _mNumber, mNumber);
It gave bad access in other layer when I called

@ int score = ((Samplecocos2dx *)this~~>getParent~~>getChildByTag)>getMNumber;
@
2. I used a method to return the score. It also gave bad access
3. I set tag for the layer itself.
this->getParent()->addChild(GameOverLayer::node(), 2, mNumber);
When I tried to get
int score = this->getTag();
Its returning
1.

Can anyone give me a solution???

Could you paste more codes or attach one demo project? :slight_smile:

I just want to access 1 variable from 1 layer to another… Whatever be the way. Please tell me. It surely doesn’t need code for ma whole game… :slight_smile: :stuck_out_tongue:

Hi Nikhil,
I use a class for all “global” objects, methods, etc.
In this post you will find and “example” (ejem…) well doesn’t pretend to be an example, but you could find an explanation there:
http://www.cocos2d-x.org/boards/6/topics/12840
‘File.h’ and ‘File.cpp’ should act as this global class, accessed by anyother through ‘File::foo’ after include it.

Another way to manage this - speaking about simple variables - is using CCFileUtils:
http://www.cocos2d-x.org/embedded/cocos2d-x/d0/ddc/classcocos2d_1_1_c_c_file_utils.html

Hope it helps,
Jordi :slight_smile: