Thread: [FTC]: Robot C
View Single Post
  #6   Spotlight this post!  
Unread 11-11-2009, 19:27
JohnFogarty's Avatar
JohnFogarty JohnFogarty is offline
Trapped under a pile of MECANUMS :P
AKA: @doctorfogarty
FTC #11444 (Garnet Squadron) & FRC#1102 (M'Aiken Magic)
Team Role: Mentor
 
Join Date: Aug 2009
Rookie Year: 2006
Location: SC
Posts: 1,582
JohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond repute
Re: [FTC]: Robot C

Quote:
Originally Posted by l0jec View Post
What you're doing is perfectly valid, but may not be the "cleanest" way.

You need to understand that a boolean true/false in ROBOTC is the same as 1 or 0 where
'true' is the same as '1' and 'false' is the same as '0'. Therefore the follow statements are all logically equivalent:
Code:
if(value == true)
if(value == 1)
if(value != false)
if(value != 0)
Since the if statement is conditional on the truth of the argument, you can format the test for truth a number of ways. Understand that the "value == true" argument is going to be evaluated as either true ('value' is true(1)) or false ('value' is false(0)) and that is what the if() statement actually looks at.
So as long as the value variable in our example here is already a boolean, there is no need to explicitly check it for truth. That is there is no need to explicitly test if true is equal to true of if false is equal to false... just pass the boolean itself to the if() statement like:
Code:
if(value)
Where does this tie into checking if a button is pressed using the joy1Btn() function?
Well because those functions return a boolean. That means when you call the function you get back either a true or a false and there is no need to see if that is not equal to 0. Just test against the returned boolean like:
Code:
if(joy1Btn(1))
{
  //do stuff
}
Now changing if(joy1Btn(1) != 0) to if(joy1Btn(1)) will not make your code behave any differently, but it will make it much more readable. As someone much wiser once said, any fool can write code that a computer can understand, but a good programmer writes code that a human can understand.

Hope this clears us some of the fog.
Tis exactly right
__________________
John Fogarty
2010 FTC World Championship Winner & 2013-2014 FRC Orlando Regional Winner
Mentor FRC Team 1102 M'Aiken Magic
"Head Bot Coach" FTC Team 11444 Garnet Squadron
Former Student & Mentor FLL 1102, FTC 1102 & FTC 3864, FRC 1772, FRC 5632
2013 FTC World Championship Guest Speaker
Reply With Quote