This site requires JavaScript, please enable it in your browser!
Greenfoot back
diy_surgery
diy_surgery wrote ...

2011/12/13

healthbar help

diy_surgery diy_surgery

2011/12/13

#
Hi, i got a problem I am trying to get a variable from a int "currentValue" in Healthbar class to be the same as a value int "health = 3" in a different class. So what i am trying, is to get the value in variable" int currentValue; " to be the same value as the variable int health = 3; in class player i'm stuck :(
delmar delmar

2011/12/13

#
You need to access the player object from the Healthbar object. Or the other way around. Either you make a method in Player that returns the health value, e.g. public int getHealth() { return health; } and then call player.getHealth() from your Healthbar object. But you have to work out how to access the player object (not the class) from your Healthbar object. Or you make a method in Healthbar: public void setValue(int value) { currentValue = value; } and call that method from player whenever the value changes. Again, you need access to the Healthbar object from the player object.
You need to login to post a reply.