Booleans

Say i have a boolean fuction such as this one:

boolean joyFL(){
  if (joyy > 130 && joyx < 125){   
    return true;    
  }
  else{
    return false;
  }
}

And i want to check if it is true in another part of my code...

is this

if (joyFL() == true){
      leftForward();
    }

the same as this

if (joyFL()){
      leftForward();
    }

Thank you!

And when you tried it what happened :wink:

if (joyy > 130 && joyx < 125){

How can you have a value greater than 130 AND less than 125?

Mark

In answer to your actual question. Yes.

I will try it i just didnt with that example because i would have to hook up my entire robot to try it.

And for holmes, if you check it properly its not the same integer one is 'joyy' and the other 'joyx'.

And thank you Ken !

But you could simplify it to

boolean joyFL()
{
return (joyy > 130 && joyx < 125);
}

holmes4:

if (joyy > 130 && joyx < 125){

How can you have a value greater than 130 AND less than 125?

Mark

Quite easily, if one is joyY and the other is joyX

OP org. question answer: Yes.

will try it i just didnt with that example because i would have to hook up my entire robot to try it.

But you could have easily created a small program to test the logic without using the robot or the rest of the code for it such as

byte joyx = 120;
byte joyy = 140;

void setup() 
{
  Serial.begin(115200);

  if (joyFL() == true)
  {
    Serial.println("true");
  }

  if (joyFL()){
    Serial.println("true");
  }
}

void loop() {}

boolean joyFL()
{
  if (joyy > 130 && joyx < 125)
  {   
    return true;    
  }
  else
  {
    return false;
  }
}