I'm having trouble carrying a variable ("score" in this instance) across multiple worlds. What I'm aiming for is my game's "game over" screen to display the score, however I'm struggling with it. I'm pretty sure I took part in a discussion a few years ago that aimed to solve the issue, but I can't find it again. Does anyone know what I could do?
My Code:
Variable Holder Class/ScoreCounter:
Game Over Screen/LoseScreen (I want to carry over the variable value to this world):
Any help would be appreciated, thanks!
import greenfoot.*; public class ScoreCounter extends Actor { int score = 0; //The variable I want to carry. public void act() { setImage(new GreenfootImage("Score: "+score,25,Color.WHITE,Color.BLACK)); } }
import greenfoot.*; public class LoseScreen extends World { public LoseScreen() { super(496, 500, 1); ScoreCounter scorecounter = getObjects(ScoreCounter.class).get(0); showText("Score: "+scorecounter.score, 248, 250); } }