This site requires JavaScript, please enable it in your browser!
Greenfoot back
ymym
ymym wrote ...

2016/10/2

Actor not in the world error

ymym ymym

2016/10/2

#
I'm making a game where an actor has to go to the other side of the screen by using floating steps. Inside my Act method, there is a if statement that removes the actor when it's on the other side. and then there is a method that makes the actor fall when it's not on the ground. when the fall method is after the if statement, 'actor not in the world' error comes up when the actor's on the other side. when it's switched, the error comes up when the actor falls. how do i solve this?
Super_Hippo Super_Hippo

2016/10/2

#
You could use one of this for the second method:
//in act method
if (getWorld() != null) fall(); //or the other one

//or at the beginning of the method itself
if (getWorld() == null) return;
danpost danpost

2016/10/2

#
You could also force an immediate exit from the act method by adding a return statement after removing the actor from the world:
getWorld().removeObject(this);
return;
Any other actions you may want to do when the actor is removed can be done before the return statement (or even before removing the actor).
You need to login to post a reply.