Hi!
I have to do a pretty basic thing, but I can't get it working. Like I've got an actor who adds "carreVert" objects, and those object should delete themselves when touching some actors. Here's the code:
I want the object to delete himself if he's touching the" xBlanc.class" objects and his piece variable is under or equal to 16. But when I compile it I get this error:
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:714)
As I understand it it deletes once and then can't find the object anymore because it's deleted wich leads to this error, but if it's deleted then it doesn't touch the" xBlanc.class" objects does it? Like I've got this code just up and it works just fine:
Why does it not work with the isTouching objects.class?
Thank you!
if(piece<=16){ if(isTouching(pionBlanc.class)||isTouching(roiBlanc.class)||isTouching(tourBlanc.class)||isTouching(fouBlanc.class)||isTouching(reineBlanc.class)||isTouching(chevalBlanc.class)){ getWorld().removeObject(this); } }
if(isAtEdge()==true){ getWorld().removeObject(this); }