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

2014/2/5

Booleans

joris0127 joris0127

2014/2/5

#
How do can I make an if-statement that is working when a boolean is true? This is my boolean:
    public boolean canSee()
    {
        double dir = Math.atan(16/distance);
        Checker checker = new Checker();
        getWorld().addObject(checker, getX(), getY());
        checker.turnTowards(bob.getX(),bob.getY());
        checker.turn((int)dir);
        return checker.detect(bob, Floor.class);
    }
Gevater_Tod4711 Gevater_Tod4711

2014/2/5

#
If you want to check whether this method returns true you just need to call the method from your if clause like this:
if (canSee()) {
    //the method canSee() returned true;
}
else {
    //the method canSee() returned false;
}
You need to login to post a reply.