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

2012/12/24

Why doesn't it work?

Ploppy Ploppy

2012/12/24

#
Why does the game get stuck and give me an error? The alien shoots thunder at the spaceship. When ever the alien shoots the thunder and the thunder reaches the bottom of the world edge, it stops the game and gives me an error. WHY?? Here is my code: Public void act() { bleh(); kalb(); } public void bleh() { setLocation(getX(), getY() +7) if( atWorldEdge() ) { getWorld().removeObject(this); } } public void kalb() { if (canSee(Spaceship.class) ) { eat(Spaceship.class); } }
SPower SPower

2012/12/24

#
When you get removed in bleh:
getWorld().removeObject(this);
you can't use methods like canSee or eat anymore, so you get an exception. Simply change act to:
public void act()
{
    kalb();
    bleh();
}
and it should work. Some advice: when you say 'I get an error', show us the error! And next time you add code, click the code button right underneath the text field and enter your code.
Ploppy Ploppy

2012/12/24

#
THANK YOU! I'm still a beginner, :P
You need to login to post a reply.