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

2016/5/13

Stopping a single method

Julian109998 Julian109998

2016/5/13

#
Hi guys, i was programming a game for a schoolproject but now i definitly stuck, i have to stop a sinlge method before it Comes to the next one : Tih is my Code : public void act() { if(isAtEdge()){ getWorld().removeObject(this); //here the Code of the object (not the hole game) has to stop if isatedge is true and the object has been removed } movement(); monsterkiller(); } public void monsterkiller(){ if(isTouching(monster.class)){ removeTouching(monster.class); getWorld().removeObject(this); //here the Code has to stop if isTouching is true and the object has been removed } } public void movement(){ setRotation(270); move(5); } at the 2 places with the // i can't find a way to stop only this Code of this object i can just stop the hole game by Greenfoot.stop I would be really thankfull for help Julian
valdes valdes

2016/5/13

#
I suppose you're getting the Error "Actor not in World" In methods movement and monsterkiller() add this line as the first line:
1
if (getWorld() == null) return;
danpost danpost

2016/5/13

#
You could also just change the one line you had //here the Code of the object (not the hole game) has to stop if isatedge is true and the object has been removed to return;
Julian109998 Julian109998

2016/5/14

#
Thank u guys :)
You need to login to post a reply.