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

2015/1/2

How do I access a score from another world?

Ruvero Ruvero

2015/1/2

#
I have a world Game1 with a variable score in an actor Score. I want to display the value of the variable score in another world, MainMenu. How would I do this?
danpost danpost

2015/1/2

#
Add the Score actor to the MainMenu world before setting that world active:
MainMenu mm = new MainMenu();
mm.addObject(/* counter reference, x-coord, y-coord */);
Greenfoot.setWorld(mm);
or you can either create and add a new actor to display the score in that world or you can draw the score value on the background of the MainMenu world (drawing the value does not retain the value in the new world -- it only allows the world to display the value). Another option would be to create a method to receive the Score object or its value in the MainMenu world and call it instead of adding the object as in the supplied code above at line 2. The method then can proceed to display the value as needed in the MainMenu class.
Ruvero Ruvero

2015/1/3

#
The first solution did the trick, thank you!
You need to login to post a reply.