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

2017/4/28

code doesn't work

kursatA kursatA

2017/4/28

#
public void actor1() { Actor cannon; cannon = getOneObjectAtOffset(0, 0, cannon.class); if (cannon !=null) { World level3; level3 = getWorld(); level3.removeObject(cannon); }
danpost danpost

2017/4/28

#
kursatA wrote...
code doesn't work
Pleeae elaborate. What message are you getting? where is the error located in the code?
kursatA kursatA

2017/4/28

#
this is the error message 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:711) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:913) at bullet2.actor1(bullet2.java:43) at bullet2.act(bullet2.java:18) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
Super_Hippo Super_Hippo

2017/4/28

#
Make sure you don't remove the object before calling the 'actor1' method.
kursatA kursatA

2017/4/28

#
what do you mean by this
Yehuda Yehuda

2017/4/28

#
There is somewhere in your code that you call this method after you removed the bullet2, you can only call a method like this if getWorld() != null. Which means the actor has to be in the world.
danpost danpost

2017/4/28

#
kursatA wrote...
Super_Hippo wrote...
Make sure you don't remove the object before calling the 'actor1' method.
what do you mean by this
What is meant is that:
public void act()
{
    // somewhere between here
    ...
    // and here
    actor1();
    ...
}
the actor is being removed from the world, probably with a line like this:
getWorld().removeObject(this);
The removing line could be in a method called between those two points.
You need to login to post a reply.