The VEX Visual Studio Code Extension has replaced VEXcode Pro V5, which is now end-of-life.
VEXcode Blocks and VEXcode Text remain actively developed and supported for all VEX platforms.
Changing a variable is a complex question when it comes to object-oriented programming languages like C++. In this article, you'll learn the fundamentals of changing variables, which include the const and lvalue concepts.
What is this "const" before the data type?
const int PI = 3.14159;
“ const” is a very important qualifier. You should use this qualifier for variables that should never change.
L-value or R-value concept
The following shows some examples:
int X = 1, Y = 3;
X = Y + 1; // Good
Y + 1 = X; // INCORRECT!
The key is for L-value:
- Variable to be modified must be put on the left side of the “=” operator.
- Operation expression should be on the right side of the “=” operator.
R-Value:
- Basically, any other expressions.
Caution: While the following is syntactically correct, it is bad:
#include "vex.h"
using namespace vex;
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
int X = 1, Y = 10;
X = (Y = (X+5)) = Y*2; // BAD! Compiler gives a warning.
Brain.Screen.print("x = %d ; y = %d ", X, Y);
}Output: X = 20; Y = 20;
Besides, when the compiler produces a warning, you should always review it carefully. Never a good idea to ignore it.