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

2017/5/26

Use a public variable in an other class

Phirippu Phirippu

2017/5/26

#
In my project I am using in the Class "Ball" a public variable named "s". Now I want use this variable "s" in the class "Highscore" and make the variable "score" in this class score = s How i can do that ? I read about many questions like my one on this forum but they dont work in my project or i dont understand it. Im sorry when the answer is clear and easy...
Trystar360 Trystar360

2017/5/26

#
Will there be only one ball or many balls and will it/they be in the world at all times?
danpost danpost

2017/5/26

#
Trystar360 wrote...
Will there be only one ball or many balls and will it/they be in the world at all times?
Presuming there is only one Ball object, and it is always in the world, then:
int score = ((Ball)getWorld().getObjects(Ball.class).get(0)).s;
should work.
Phirippu Phirippu

2017/5/27

#
Thank you danpost, it is working :)
You need to login to post a reply.