Changing Variable value from another class

VonnCC picture VonnCC · Sep 20, 2013 · Viewed 19.5k times · Source

I have an integer(levelstatus) in class A(LevelSelectScene) and I want to change it in class B(GameScene), is it possible?

here is my code:

(Code in GameScene)

public class levelComplete()
{

levelSelectScene.getInstance.levelstatus=1;

}

LevelSelectScene has an public integer levelstatus.

and after an event happens, levelComplete will trigger and will change the value of levelstatus from null to 1.

Answer

Suresh Atta picture Suresh Atta · Sep 20, 2013

Yes.

Make your levelstatus variable as static.

Because I guess you need to change that variable in each level class.

That means,you are wanting to access that variable through out the whole Game(All levels).

And also,Declare that variable in a Util class(proposing a name LevelUtil),Since it wont attach to a single level.