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

2012/10/14

I Need Help!

Game/maniac Game/maniac

2012/10/14

#
How do I fix 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:663) at greenfoot.Actor.getX(Actor.java:157) at Worldy.StareX(Worldy.java:41) at enemyTankHead.Controll(enemyTankHead.java:45) at enemyTankHead.act(enemyTankHead.java:40) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) You can get the source code here.
Morran Morran

2012/10/14

#
I haven't looked at the source code, but maybe you were calling getX() in the constructor of your class. You cannot call getX() or getY() inside of the constructor of your class.
Game/maniac Game/maniac

2012/10/14

#
It's not that it was working fine till I added a game over I think it is becuase I removed an actor then the getX() was called but the object it was trying to get the x coordinate from was removed so it couldn't do that, the only problem I have is trying to find out what I need to change to make it work
danpost danpost

2012/10/14

#
This error occurs when the health of the tank is depleted and the tank is removed from the world. The enemy tank is trying to get the tanks x and y, but it is no longer in the world. In the Worldy world class, change StareX and StareY to the following:
public int StareX()
{
    if (tank.getWorld != null) return tank.getX();
    return getWorld().getWidth() / 2;
}

public int StareY()
{
    if (tank.getWorld() != null) return tank.getY();
    else return getWorld().getHeight() / 2;
}
With this code, the enemy tank will fire bullets toward the middle of the world after the tank is removed.
Game/maniac Game/maniac

2012/10/14

#
thanx!!!
You need to login to post a reply.