When I try to shoot my randomly appearing enemy an error pops up saying
"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."
Although, In my world I am pretty sure that I added the code for the randomly appearing enemy. Also he only appears once and I would like him to appear every 30 seconds or so.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ammo here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ammo extends Actor
{
boolean removed;
/**
* Act - do whatever the ammo wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public ammo()
{
removed = false;
}
public void act()
{
if(removed)
return;
move();
killEnemy();
}
public void move()
{
if(getY()<=0)
{
removed = true;
getWorld().removeObject(this);
return;
}
setLocation(getX(), getY()-10);
}
public void killEnemy()
{
Actor enemy = getOneObjectAtOffset(0,0,Enemy.class);
if(enemy != null)
{
getWorld().removeObject(enemy);
getWorld().removeObject(this);
}
}
}

