This site requires JavaScript, please enable it in your browser!
Greenfoot back
rachpaguia@gmail.com
rachpaguia@gmail.com wrote ...

2017/3/16

terminal window

does anyone know how to make the terminal window stop appearing? there have been plenty of times wherein my program stops because of it :-(
my program also stops every time an object is removed, my program consist of the if iskeydown ... then remove object , why is this happening
Super_Hippo Super_Hippo

2017/3/17

#
The terminal window does not pop up to annoy you. It shows you where the error in your code is.
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.getY(Actor.java:177)
	at L.act(L.java:26)
	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)
what does this mean?
Super_Hippo Super_Hippo

2017/3/17

#
It means that in line 26 of the L class, you call the getY method which requires the object to be in a world while it is not in a world.
public class L extends Actor
{
public L()
    { //this is to resize the image
        GreenfootImage image = getImage();
        image.scale(330, 150);
    }
         public void act()
{
{
        setLocation (getX(), getY()+6);
        if (Greenfoot.isKeyDown("l")) 
        {
           getWorld().removeObject(this); // removing L actor on 'l' press
           Greenfoot.playSound("poppy.wav");// playing 'pop' when L actor is removed
        }
  }
 if (getY() == getWorld().getHeight()-1)
{
    ((bg)getWorld()).gameOver();
    return;
}
}
}
  
do you know which part of my code asks that command?
Super_Hippo Super_Hippo

2017/3/17

#
Remove lines 10 and 17 and change 'if' in line 18 to 'else if'. Right now, when pressing "l", the object is removed from the world and after that, line 18 tries to get its y-coordinate but it doesn't have one anymore since it was removed.
Thank you so so much!
You need to login to post a reply.