Before Variables: 3. Oversimplified Parameters — The Control Room 🟢
<aside>
$$ {\Large\text{A variable is a named place where Vex temporarily keeps a value.}} $$
</aside>
| Type | Stores | Example | Variable | Attribute |
|---|---|---|---|---|
int |
Whole numbers | 10 |
int i = 10; |
i@i |
float |
Decimal numbers | 3.14 |
float f = 3.14; |
f@f |
vector |
3 values | {1,0,0} |
vector v = {1,0,0}; |
v@v |
string |
Text | "hello" |
string s = "hello"; |
s@s |
matrix |
A matrix | ident() |
matrix m = ident(); |
4@m |
Variables let us name information, reuse it, and change it easily.
float speed = 5.0;
Create a variable called
speedand put5.0in it.
Then you can use that value:
@P.y += speed;
<aside> ⚠️
This creates a VEX variable.
float speed = 5.0;
This creates an attribute called speed.
f@speed = 5.0;
</aside>

<aside>
$$ {\Large\begin{array}{c}\text{VARIABLE} \quad \text{temporary information used while your VEX code is running.}\\[8pt]\text{ATTRIBUTE} \quad \text{data stored as part of the geometry.}\end{array}} $$
</aside>
Variables give values a name so we can refer to, reuse, and change them easily.
The name speed still refers to the same variable, but its value has changed.
float speed = 5.0;
speed = 10.0;
A variable has a type that describes what kind of value it stores.
float speed = 5.0;
vector direction = {0,1,0};
int count = 10;
VARIABLE — A temporary piece of information used while your VEX code is running.
ATTRIBUTE — Data stored on the geometry and available to other nodes.
| Type | Stores | Example | Variable | Attribute |
|---|---|---|---|---|
int |
Whole numbers | 10 |
int i = 10; |
i@i |
float |
Decimal numbers | 3.14 |
float f = 3.14; |
f@f |
vector |
3 values | {1,0,0} |
vector v = {1,0,0}; |
v@v |
string |
Text | "hello" |
string s = "hello"; |
s@s |
matrix |
A matrix | ident() |
matrix m = ident(); |
4@m |
The type tells VEX what kind of value it can hold.
The same type can be used for a variable or stored as a geometry attribute.
// Create an integer variable from the "a" parameter
int i = chi("a");
// Store the integer as an integer attribute
i@i = i;
// Create a float variable from the "b" parameter
float f = chf("b");
// Store the float as a float attribute
f@f = f;
// Create a vector variable from the "c" parameter
vector v = chv("c");
// Store the vector as a vector attribute
v@v = v;
// Create a string variable from the "d" parameter
string s = chs("d");
// Store the string as a string attribute
s@s = s;
// Create a matrix variable from the "e" parameter
matrix m = ch4("e");
// Store the matrix as a 4×4 matrix attribute
4@m = m;
Variables can be used in calculations and expressions.
| Operation | Meaning | Example |
|---|---|---|
+ |
Add | speed + 3 |
- |
Subtract | speed - 1 |
* |
Multiply | speed * 2 |
/ |
Divide | speed / 2 |
float speed = 5.0;
float doubled = speed * 2;
float faster = speed + 3;
The same operations work with other numeric types, such as int:
int count = 5;
int doubled = count * 2;
int more = count + 3;