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

2015/6/12

Game stops when a tomatoPile runs out.. How do I fix this?

Lednarg Lednarg

2015/6/12

#
Anyone know how to get the game to not stop? Help is greatly appreciated!
/**
     * Is there any food here where we are? If so, try to load some!
     */
    public void checkFood()
    {
        // check whether there's a tomato pile here
        TomatoPile tomatoPile = (TomatoPile) getOneIntersectingObject(TomatoPile.class);
        if(tomatoPile != null)
        {
            loadTomato();
            turnHome();
            int deltaX = tomatoPile.getX() - getX();
            int deltaY = tomatoPile.getY() - getY();
            setRotation((int) (180 * Math.atan2(deltaY, deltaX) / Math.PI));
        }
    }
lordhershey lordhershey

2015/6/12

#
well, if the tomato pile is empty, will the bug do anything or will is just sit there?
azazeel azazeel

2015/6/12

#
i didn't get the question clearly
Lednarg Lednarg

2015/6/12

#
lordhershey wrote...
well, if the tomato pile is empty, will the bug do anything or will is just sit there?
it just sits there and an error pops up saying there is something wrong with int deltaX = tomatoPile.getX() - getX();
azazeel azazeel

2015/6/12

#
what is the exact error message ?
Lednarg Lednarg

2015/6/12

#
azazeel wrote...
what is the exact error message ?
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. at greenfoot.Actor.failIfNotInWorld(Actor.java:681) at greenfoot.Actor.getX(Actor.java:157) at Alien.checkFood(Alien.java:71) at Alien.act(Alien.java:56) at greenfoot.core.Simulation.actActor(Simulation.java:594) at greenfoot.core.Simulation.runOneLoop(Simulation.java:552) at greenfoot.core.Simulation.runContent(Simulation.java:215) at greenfoot.core.Simulation.run(Simulation.java:205)
azazeel azazeel

2015/6/12

#
that's what exactly i want, the error so in my opinion may be something wrong in alien.java, find some line that remove object getWorld().removeObject(bla bla bla seems you remove that object
Lednarg Lednarg

2015/6/12

#
So I think I found the logic problem, but I need to be able to check when the tomatoe pile gets to only one left. but I need to do it from the alien class. I'm not sure of the code / syntax to do that. So, basically I need to be able to execute the if (tomatoes = 1) from the takeOne() method in the tomatoe class. Is this possible?
azazeel azazeel

2015/6/12

#
http://www.greenfoot.org/files/javadoc/greenfoot/World.html#numberOfObjects() but you still have to check whether it is empty or not
You need to login to post a reply.