I have a 2 bullet actors and 2 enemy actors. When I shoot the bullet and it touches the zombie, everything works fine. The zombie has health and when it loses it all, it gets deleted from the world. However, when the bullet gets to the end of the screen, it gives this error code
This is my bullet code
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:711) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913) at BulletLeft.killZombie(BulletLeft.java:29) at BulletLeft.act(BulletLeft.java:24) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class BulletLeft here. * * @author (your name) * @version (a version number or a date) */ public class BulletLeft extends Actor { boolean removed = false; boolean destroy = false; /** * Act - do whatever the BulletLeft wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(-6); if(getX() <= 1 || getX() >= 1599 || getY() >=822 || getY() <=1 || destroy == true) { getWorld().removeObject(this); } killZombie(); } public void killZombie() { MyWorld lWorld = (MyWorld)getWorld(); ZombieRight zombieRight = (ZombieRight)getOneObjectAtOffset(0, 0, ZombieRight.class); ZombieLeft zombieLeft = (ZombieLeft)getOneObjectAtOffset(0, 0, ZombieLeft.class); if(zombieRight != null) { zombieRight.loseHealth(); getWorld().removeObject(this); } else if(zombieLeft != null) { zombieLeft.loseHealth(); getWorld().removeObject(this); } } }