so i have been trying to remove the Rocket and the Rat at the same time when they come into contact with one another which works fine. However, I also tried to remove the Rocket when it reaches world edge and when the rocket reaches world edge, it gives me this: 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.
is there a way to get the Rocket removed upon contact with the Rat AND get the "uncontacted" Rockets to be get removed at world edge
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Rocket here. * * @author (your name) * @version (a version number or a date) */ public class Rocket extends Animal { /** * Act - do whatever the Rocket wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(); disappear(); Eat(); } /** * The rockets disappear at world edge */ public void disappear() { if (atWorldEdge()) { getWorld().removeObject(this); } } /** * Gets rid of the rat */ public void Eat() { if (canSee(Rat.class)) { eat(Rat.class); getWorld().removeObject(this); } } }