I am working on a project that calls for the removal of the player object, but once the object has been removed the world stops. A few different objects use the player object, so I assumed something like if(player!=null) would work.
It didn't.
The error looks like this:
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:655)
at greenfoot.Actor.getX(Actor.java:157)
at NyanGame.createRainbow(NyanGame.java:38)
at ForestWorld.act(ForestWorld.java:35)
at greenfoot.core.Simulation.actWorld(Simulation.java:513)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:456)
at greenfoot.core.Simulation.runContent(Simulation.java:204)
at greenfoot.core.Simulation.run(Simulation.java:194)
Note the piece of code in question:
if(player != null)
{
createRainbow(player);
}
is located in the world's code, if that helps.