Hello been trying to get this done for a while now. I've written a method in my actor subclass to check if it isTouching the player and once it is it runs some basic code and then removes itself. but if the actor gos out of play without touching the player it gives me the error msg
ive tried a few things to stop to statement from running if the actor isAtEdge() or getY() > 0 but these still give the same errors
heres the full class
java.lang.IllegalStateException: Actor not in world. An attemp 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.
public class Questions extends fallingActors
{
/**
* Act - do whatever the Questions wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
protected static boolean answerCorrect;
public void act()
{
answerCorrect = false;
setLocation();
checkRemove(this);
collideWithPlayer();
}
private void collideWithPlayer()
{
if(isAtEdge() == false)
{
Actor player = getOneIntersectingObject(player.class);
//send question
if(player != null)
{
Greenfoot.ask("hello world");
World w = getWorld();
GameWorld.score += 1;
//after asking question remove object
w.removeObject(this);
}
}
}
}
