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

2014/11/25

Boolean true false statements

zyxelementxyz zyxelementxyz

2014/11/25

#
I am trying to make a pinball bounce a random direction off of a bumper but am at a stalemate with my knowledge. I have written: public boolean onBumper() { if(isTouching(Bumper.class)) { return true; } else { return false; } if(onBumper(true)) { setRotation(Greenfoot.getRandomNumber(360)); } else { move(10); } } This keep returning an error but to my knowledge it seems like this should work just fine. Can someone please help explain this to me! Thank you so much.
davmac davmac

2014/11/25

#
Please use code tags when you post code.
Super_Hippo Super_Hippo

2014/11/25

#
The method should end after the 'return false'. The method either returns true or false, it can't do something after that. The rest should be in the act method. And you have to change 'onBumper(true)' to 'onBumper()' (or 'onBumper()==true', which is the same).
danpost danpost

2014/11/25

#
Another thing -- with the code as it is written (referring to the last 'if-else' segment), you have no movement to the pinball after contact with the bumper. It will just rotate in place (it will still be on the bumper on following act cycles).
You need to login to post a reply.