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

2011/3/6

Can someone spot the error of my ways?

m.legere1323 m.legere1323

2011/3/6

#
Greenfoot says "missing return statement"...so it wont compile =( but I thought I did have one? public boolean canSeeLine() { if (getRotation() == 0) { Actor bLine = getOneObjectAtOffset(5, 0, BlueLine.class); if(bLine != null) { return true; } else { return false; } } }
JL235 JL235

2011/3/6

#
If rotation is not 0 then it will not enter the if statement, and on those occasions it will not encounter a return statement.
delmar delmar

2011/3/6

#
Another small style thing: Instead of writing if(bLine != null) { return true; } else { return false; } you could also write return bLine != null; It does exactly the same thing. (Think about it - if (bLine != null) is true, it returns true...). Your way of writing it is not wrong, just longer than necessary.
m.legere1323 m.legere1323

2011/3/6

#
@JL235 *facepalm* thank you =) @delmar thank you, its always good to see a shorter way of writing the code
You need to login to post a reply.