Hello,
I created a method in the Monsters.class which deals damages to the Gear.class. In the Gear.class i created a method that lower the gear's life when it takes damage from a monster (by touching it), and when its life is 0, it should be removed.
Here is the code of the Monsters class
and here's the gear's code:
The problem is that, when i play and my gear is out of health and it should die, the greenfoot terminal window appears and tell me:
"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."
and shows that the fault is in the line that i wrote in bold...
I think that when the Gear is removed, the Monster's class doesn't find the monster that it's meant to damage... but how to deal with that?
Thank you ^^
private static final int damage = 5;
private void damageGears()
{
[b]Gear1 gear = (Gear1) getOneIntersectingObject(Gear1.class);[/b]
if (gear != null)
{
gear.takeDamage(damage);
}
}private static int Life = 3000;
public void takeDamage(int damage)
{
Life = Life - damage;
if(Life <=0)
{
dead = true;
getWorld().removeObject(this);
}
}

