ROBOTC.net forums
http://robotc.net/forums/

!= condition and const short
http://robotc.net/forums/viewtopic.php?f=11&t=11398
Page 1 of 1

Author:  mcabre204 [ Wed Jun 03, 2015 11:23 am ]
Post subject:  != condition and const short

While trying to learn about how to program the VEX LCD screen I came across this sample code. The full code is actually in the robotc sample programs. The first thing I don't understand is the != condition, which can be seen below. In the full code you can see the const short near the top which is unfamiliar to me. If someone could help it would be much appreciated.
Code:
task main()
{
//Declare count variable to keep track of our choice
int count = 0;
 
//------------- Beginning of User Interface Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Loop while center button is not pressed
while(nLCDButtons != centerButton)
{
//Switch case that allows the user to choose from 4 different options
switch(count){
case 0:
//Display first choice
displayLCDCenteredString(0, "Autonomous 1");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count = 3;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 1:
//Display second choice
displayLCDCenteredString(0, "Autonomous 2");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count--;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 2:
//Display third choice
displayLCDCenteredString(0, "Autonomous 3");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count--;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
break;
case 3:
//Display fourth choice
displayLCDCenteredString(0, "Autonomous 4");
displayLCDCenteredString(1, "<         Enter        >");
waitForPress();
//Increment or decrement "count" based on button press
if(nLCDButtons == leftButton)
{
waitForRelease();
count--;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count = 0;
}
break;
default:
count = 0;
break;
}
}
//------------- End of User Interface Code ---------------------

Author:  Tabor473 [ Wed Jun 03, 2015 12:01 pm ]
Post subject:  Re: != condition and const short

!= means not equal to. This is the same as writing !(nLCDButtons == centerButton) which is read "not" nLCDButtons equals centerButton.

So const short would be difficult to google but that is mainly because it is 2 separate things. Const(constant) means that the variable does not change after it is set initially. Defining which number refers to which button would be a good example because no other code should change which number responds to which button. Short is a data type just like int or char that stores numbers just like int but takes up less space in the robots memory. Shorts are good if you don't need a variable to be able to store numbers in the billions.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/