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

2014/4/11

Problem in coliding with correct answer

samarthj samarthj

2014/4/11

#
In making a quiz, when the the flag of a country (an image) is collided with the wrong answer (another image) the the flag reaches at its starting position. I have used setLocation for that in the following way.
setLocation(1204, 114);
But if I collide with the correct answer I am facing the terminal window. This is the code that I used to do some thing when I collide with the right and the wrong answer.
if(isTouching(Blank1.class))
        {
            getWorld().removeObject(this);
        }   
        if(isTouching(Blank2.class) || isTouching(Blank3.class) || isTouching(Blank4.class) || isTouching(Blank5.class) || isTouching(Blank6.class))
        {
            setLocation(1204, 114);
        }
This is the terminal error that I get. 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.isTouching(Actor.java:925) at UaeFlag.act(UaeFlag.java:32) 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) Please help me with the alterations I can make to make it right.
danpost danpost

2014/4/11

#
Either switch the two 'if' blocks or use an 'else' between them.
samarthj samarthj

2014/4/12

#
Thanks a lot for quick revert and help yes it solves the problem. Highly appreicate your quick revert.
You need to login to post a reply.