I'm making some circles play tag. I want the one who is it to find the locations of all the other players. I've done that but when I start the scenario I get a run time error printed here:
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:663)
at greenfoot.Actor.getX(Actor.java:157)
at Red_Player.It(Red_Player.java:22)
at Red_Player.act(Red_Player.java:8)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
The 1st, 4th, and 5th lines are red and the rest is gray.
here is the code in question:
The rest isn't a problem as far as I know. I know that I'm missing something. It may be a list but I'm not sure. Any help is always appreciated. And all of the referenced actors are in the world. And I use "this" because it is in the "Red_Player" class. It needs to know it's own position so it can use the distance formula between it and the other actors. I assumed that "this" would only be used for the actor that the file is for. When I tried to find the position for it the way i did for the others, I got the same error but for a different line. If you need the rest of the file I'd be happy to post it. The Green_Player, Blue_Player, etc. are blank files currently if that helps.
Actor green = new Green_Player(); Actor blue = new Blue_Player(); Actor orange = new Orange_Player(); Actor pink = new Pink_Player(); Actor yellow = new Yellow_Player(); Actor purple = new Purple_Player(); int redX = this.getX(); int redY = this.getY(); int greenX = green.getX(); int greenY = green.getY(); int blueX = blue.getX(); int blueY = blue.getY(); int orangeX = orange.getX(); int orangeY = orange.getY(); int pinkX = pink.getX(); int pinkY = pink.getY(); int yellowX = yellow.getX(); int yellowY = yellow.getY(); int purpleX = purple.getX(); int purpleY = purple.getY();