I have a game that's supposed to remove an actor whenever it eats it, and it does, but it also gives an error message and pauses the program. How can I stop this?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class nonPlayerCharacters here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class nonPlayerCharacters extends insects
{
int x;
int y; boolean food;
/**
* Act - do whatever the nonPlayerCharacters wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public boolean atWorldEdge()
{
if (getX() <= 5 || getX() >= getWorld() . getWidth() -5 || getY() <= 5 || getY() >= getWorld() . getHeight() -5)
{
return true;
}
else
{
return false;
}
}
public int movement(int x)
{
int q = 0;
while (q<30)
{
move(x); delay(1); q++; kill ();
}
return (x);
}
public int delay (int z)
{
Greenfoot.delay(z);
return(z);
}
public void borderTurn ()
{
if (atWorldEdge())
{
turnTowards(500,300);
atWorldEdge();
movement(1); delay(1);
}
}
public int playerDetection(int a)
{
Actor playerCharacter;
playerCharacter = getWorld().getObjects(playerCharacter.class).get(0);
turnTowards(playerCharacter.getX()*a, playerCharacter.getY()*a);
return(a);
}
public void kill ()
{
if (isTouching(playerCharacter.class)&&food)
{
World world;
world = getWorld();
Actor superfood;
superfood = this.getOneObjectAtOffset(0, 0, superfood.class);
if (getWorld() != null){getWorld().removeObject(this);}
counter.addScore(); counter.addScore();
}
if (isTouching(playerCharacter.class)&&!food)
{
World world;
world = getWorld();
Actor food;
food = this.getOneObjectAtOffset(0, 0, food.class);
getWorld().getObjects(food.class);
if (getWorld() != null){getWorld().removeObject(this);}
counter.addScore();
}
}
public void act()
{
}
}

