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

Report as inappropriate.

davecoolkid
davecoolkid presents ...

2012/5/2

Nyan Cat

I can't get the bullets on the edge of the map to dissapear without getting an error, please help

3076 views / 14 in the last 7 days

1 vote | 0 in the last 7 days

Tags: game with-source

open in greenfoot
Your browser does not support the canvas tag.
GriffonGriffon

2012/5/2

I've had this problem several times, I found that the getWorld().removeObject(this); statement has to be the very last statement in the act() method or put an if statement that would be false if it's no longer there, here is the reason, the act() method will always executes all statements in it and you get the error if the actor is gone before the act() method is done here is how I fixed the error: public class Bullet extends SmoothMover { private boolean remove = false; public void act() { movearound(); dissapear(); eatAsteroid(); if(remove) getWorld().removeObject(this); } public void dissapear() { if (atWorldEdge()) { remove = true; } } public void movearound() { move(7.0); } public void eatAsteroid() { if(canSee(Asteroid.class)) { eat(Asteroid.class); remove = true; } } }
danpostdanpost

2012/5/3

I fixed by just changing 'eatAsteroid();' to 'if (getWorld != null) eatAsteroid();'.
danpostdanpost

2012/5/3

Sorry, that was supposed to be: if (getWorld() != null) eatAsteroid();
DutaDuta

2012/5/3

Also: public void act() { if(condition) { getWorld().removeObject(this); return; } //Any code here won't raise errors if the actor is removed, because the code exits out of the method through the return statement. }
solo1512solo1512

2012/5/3

Have the rocks kill nyan cat. public void killNyanCat(Class clss) Actor actor = getOneObjectAtOffset(0,0,clss); if(actor != null) { getWorld().removeObject(actor); } this is the method signature: killNyanCat(NyanCat.class);
solo1512solo1512

2012/5/3

Fix that bug cuz when it goes into the upper righthand corner it pauses the application!
A new version of this scenario was uploaded on Thu May 03 23:33:12 UTC 2012 Fixed error, Thanks everyone for responding so quickly. :)
A new version of this scenario was uploaded on Thu May 03 23:34:04 UTC 2012 Fixed error, Thanks everyone for responding so quickly. :)
davecoolkiddavecoolkid

2012/5/3

Thanks everyone, I fixed the error :)
A new version of this scenario was uploaded on Thu May 03 23:35:18 UTC 2012 Fixed error, Thanks everyone for responding so quickly. :)

See all comments

Want to leave a comment? You must first log in.

Who likes this?

THE_MASTER_PUMA