I want the variable armour to be avalabile for all the worlds so when the world changes the value remains the same as in the previous world (it is declared public in the actor's code)
import greenfoot.*; public class Mario extends Actor { private int speed = 7; private int vSpeed = 0; private int acceleration = 2; private int jumpStrength = 25; public int armour = 3; public void act() { if (! getWorld().getObjects(GameOver.class).isEmpty()) { return; } checkKeys(); attack(); checkFall(); hitGoomba(); hitCastle_l1(); hitCastle_l2(); checkArmour(); } private void checkKeys() { if(Greenfoot.isKeyDown("left")) { moveLeft(); } if(Greenfoot.isKeyDown("right")) { moveRight(); } if(Greenfoot.isKeyDown("up")) { jump(); } } public void checkFall() { if(onGround() && vSpeed != -jumpStrength) { vSpeed=0; if (Greenfoot.isKeyDown("left") == Greenfoot.isKeyDown("right")) { setImage("Goku_idle.png"); } } else { setImage("Goku_jump.png"); fall(); } } public boolean onGround() { Actor under = getOneObjectAtOffset ( 0, getImage().getHeight()/2, Ground.class); return under != null; } public void fall() { setLocation ( getX(), getY() + vSpeed); vSpeed = vSpeed + acceleration; } public void jump() { if (onGround()) { vSpeed = - jumpStrength; } } public void hitGoomba() { Actor goomba = getOneIntersectingObject(Goomba.class); if(goomba != null) { armour = armour - 1; getWorld().removeObject(goomba); } } public void hitCastle_l1() { Actor castle = getOneIntersectingObject(Castle.class); if(castle != null) { Greenfoot.setWorld(new Level_2()); } } public void hitCastle_l2() { Actor castle = getOneIntersectingObject(Castle_l2.class); if(castle != null) { Greenfoot.setWorld(new Final_level()); } } public void moveRight() { setLocation ( getX() + speed, getY()); setImage("Goku_move_right.png"); } public void moveLeft() { setLocation ( getX() - speed, getY()); setImage("Goku_move_left.png"); } public void attack() { if("space".equals(Greenfoot.getKey())) { getWorld().addObject(new Sphere_right(), getX() + 5, getY()); setImage("Goku_attack.png"); } } public void checkArmour() { Actor sphere = getOneIntersectingObject(Sphere_left.class); if(sphere != null) { armour = armour - 1; getWorld().removeObject(sphere); } if(armour == 0) { getImage().setTransparency(0); World myWorld = getWorld(); GameOver gameover = new GameOver(); myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2); Greenfoot.stop(); } } }