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

2013/2/15

Dissapear on edge error!?!?!?!!? PLZ HELP ME

1
2
Eli.A Eli.A

2013/2/15

#
Okay, thank you very much for everything.
Gingervitis Gingervitis

2013/2/15

#
Glad to help!
danpost danpost

2013/2/15

#
After removing line 30 above, your bullet is not removed at the time it hits a balloon (do not remove that line). The 'IllegalStateException' occurs when a balloon is hit and the bullet is removed from the world because the next statement tries to find the edge of the world when it is no longer in a world to check for any edges on. To avoid this, just put a 'return; statement after line 30 to force an exit from the method, preventing the world-edge checking from being executed. For disappearing the balloon, you can add a 'destroy' method to the Balloon class to ask 'if (getX()<10)' (calling the 'destroy' method from its 'act' method, of course).
Eli.A Eli.A

2013/2/15

#
danpost wrote...
After removing line 30 above, your bullet is not removed at the time it hits a balloon (do not remove that line). The 'IllegalStateException' occurs when a balloon is hit and the bullet is removed from the world because the next statement tries to find the edge of the world when it is no longer in a world to check for any edges on. To avoid this, just put a 'return; statement after line 30 to force an exit from the method, preventing the world-edge checking from being executed. For disappearing the balloon, you can add a 'destroy' method to the Balloon class to ask 'if (getX()<10)' (calling the 'destroy' method from its 'act' method, of course).
Actually, Danpost, I can get rid of the balloons when I remove line 30. Also, can you explain what a "destroy method" is? I know tht this is probably a stupid question, but hey I'm a n00b
danpost danpost

2013/2/15

#
Eli.A wrote...
Actually, Danpost, I can get rid of the balloons when I remove line 30.
The balloon is being removed on line 29. If you want the bullet to disappear when it hits a ballon, then leave line 30 in your code and add a 'return;' statement immediately after it. You are using a 'destroy' method in the Bullet class which has code to remove the object when it reaches the edge of the world. I was just saying that you could do something similar in the Balloon class to remove any ballon that reaches the edge of the world before being hit by a bullet.
Eli.A Eli.A

2013/2/15

#
danpost wrote...
Eli.A wrote...
Actually, Danpost, I can get rid of the balloons when I remove line 30.
The balloon is being removed on line 29. If you want the bullet to disappear when it hits a ballon, then leave line 30 in your code and add a 'return;' statement immediately after it. You are using a 'destroy' method in the Bullet class which has code to remove the object when it reaches the edge of the world. I was just saying that you could do something similar in the Balloon class to remove any ballon that reaches the edge of the world before being hit by a bullet.
Okay, you fixed the bullet going away when I shoot, but the balloon is not vanishing when ti reaches the end. I put code in the balloon that should make it work but when I compile, Greenfoot gives me a syntax error. The error is, " World is not public in Greenfoot.actor; can't be accessed from outside package" The code is below
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Ballon here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Ballon extends Actor
{
    /**
     * Act - do whatever the Ballon wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
{
  move(-4);
   if (Greenfoot.getRandomNumber(100)<50)
{
 setLocation(getX(),getY() + 5);
}
if (getX()<10)
{
// the line under this is where Greenfoot is saying the error is
 world.removeObject(this);
}
}
}
danpost danpost

2013/2/15

#
Replace your comment line (line 24) with
Wold world = getWorld();
Eli.A Eli.A

2013/2/15

#
YES!!! Thank you so much!!!
You need to login to post a reply.
1
2