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

2013/12/18

Help with this error?

askdave askdave

2013/12/18

#
http://www.greenfoot.org/scenarios/10459 The game is working fine, but at the end of the game I'm getting an error "java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed." Can anyone help me with this? I want the ball and score to stay removed at the end of the game, but I can't figure out why the remove items is causing an error.
danpost danpost

2013/12/18

#
You probably have code that is trying to be executed in the Ball class that requires it to be in the world after it is removed from the world.
askdave askdave

2013/12/18

#
How can I stop the program from running once I remove the objects? This is how I end my game now. But it still runs the Keyboard Check.
public void endGame()
    {
        removeObjects(getObjects(null));
        setBackground(new GreenfootImage("End.png"));  
        Greenfoot.stop();
    }
danpost danpost

2013/12/18

#
Your 'tryToEatPlayer' calls the Dodgeball class method 'endGame' which removes all actors from the world (including the Dodgeball object. Then your next call in the Dodgeball class 'act' method is 'edgeBounce' which in turn calls 'atWorldEdge' which requires the object to be in the world. Since you already have a boolean return value from the 'tryToEatPlayer' method, you can use it to prevent execution of the rest of the 'act' method when the Player object is encountered by the dodgeball.
// in act -- instead of 
tryToEatPlayer();
// use
if (tryToEatPlayer()) return;
askdave askdave

2013/12/18

#
You're incredible. Thank you so much.
You need to login to post a reply.