Variables#
Introduction#
The Variables blocks in VEXcode V5 allow for storing and managing data, including numbers, Boolean values, lists, and 2D lists.
To make a variables blocks appear you must first create a variable. Variables are created using the Make buttons in the Variables category. All variables are global by default, meaning they can be used anywhere in the project.
Below is a list of available blocks:
Numeric Variables - Store and modify numbers.
numeric variable – Returns the value of a numeric variable.
set numeric variable – Assigns a value to a numeric variable.
change numeric variable – Increases or decreases a numeric variable by a set amount.
Boolean Variables – Store True or False values.
Boolean variable – Returns the value of a Boolean variable.
set Boolean variable – Assigns a True or False value to a Boolean variable.
Lists – Store and manage collections of values.
list item – Returns a value from a list based on its position.
replace list item – Updates a specific item in a list.
set list items – Assigns values to a list.
length of list – Returns the number of items in a list.
2D Lists – Store and manage collection of values in a grid.
2D list item – Returns a value from a specific row and column in a 2D list.
replace 2D list item – Updates a specific item in a 2D list.
set 2D list items – Assigns values to a 2D list.
length of 2D list – Returns the number of rows or columns in a 2D list.
Numeric Variables#
numeric variable#
The numeric variable reporter block is used to return the numeric value assigned to the variable.
(myVariable)
Parameter |
Description |
|---|---|
This block has no parameters. |
Example
当开始
[Display the value of the variable plus two.]
设定 [myVariable v] 为 [2]
在屏幕上打印 ((myVariable) [math_plus v] [2])▶
set numeric variable#
The set numeric variable block assigns a value to a numeric variable.
设定 [myVariable v] 为 [1]
Parameter |
Description |
|---|---|
variable |
The numeric variable to assign a value to. Users can select an existing variable, rename it, or delete it. |
value |
The number assigned to the variable (can be a whole number, decimal, or numeric block). |
Example
当开始
[Set a variable to 10 and display it.]
设定 [myVariable v] 为 [10]
在屏幕上打印 (myVariable)▶
change numeric variable#
The change numeric variable block increases or decreases a variable’s value by a given amount.
将 [myVariable v] 改变 (1)
Parameter |
Description |
|---|---|
variable |
The numeric variable to modify. Users can select an existing variable, rename it, or delete it. |
value |
The amount to increase or decrease the variable by. |
Example
当开始
[Increase the variable by 5 and display it.]
设定 [myVariable v] 为 [10]
将 [myVariable v] 改变 [5]
在屏幕上打印 (myVariable)▶
Boolean Variables#
boolean variable#
The Boolean variable block is used to return either a True or False value.
<myBoolean>
Parameter |
Description |
|---|---|
This block has no parameters. |
Example
当开始
[Display a message if the variable is set to True.]
设定 [myBoolean v] 为 <true v>
如果 <myBoolean> 那么
在屏幕上打印 [Boolean is True!]▶
结束
set Boolean variable#
The set Boolean variable block assigns a True or False value to a Boolean variable.
设定 [myBoolean v] 为 <true v>
Parameter |
Description |
|---|---|
variable |
The Boolean variable to assign a value to. Users can select an existing variable, rename it, or delete it. |
value |
A Boolean value:
|
Example
当开始
[Display different messages based on the Boolean value.]
设定 [myBoolean v] 为 <true v>
如果 <myBoolean> 那么
在屏幕上打印 [It's true!]▶
否则
在屏幕上打印 [That's false...]▶
结束
Lists#
list item#
The list item block is used to return the value of an item in a list.
((1) 元素 [myList v])
Parameter |
Description |
|---|---|
index |
The position of the item in the list (starting at 1). |
variable |
The list variable to return an item from. Users can select an existing list, rename it, or delete it. |
Example
当开始
[Display the second item from a list.]
设定 [myList v] 为 (5) (1) (9)
在屏幕上打印 ((2) 元素 [myList v])▶
replace list item#
The replace list item block updates a specific item in a list.
将 [1] 元素 [myList v] 置换为 [1]
Parameter |
Description |
|---|---|
index |
The position of the item in the list (starting at 1). |
variable |
The list variable containing the item to modify. Users can select an existing list, rename it, or delete it. |
value |
The new value assigned to the specified list item. |
Example
当开始
[Replace the first item in a list with 4.]
设定 [myList v] 为 (5) (1) (9)
将 (1) 元素 [myList v] 置换为 (4)
在屏幕上打印 ((1) 元素 [myList v])▶
set list items#
The set list items block sets every item in the list to the entered values.
设定 [myList v] 为 (0) (0) (0)
Parameter |
Description |
|---|---|
variable |
The list variable being assigned values. Users can select an existing list, rename it, or delete it. |
values |
The values to store in the list, entered as individual items. |
Example
当开始
[Display the last item in a list.]
设定 [myList v] 为 (1) (2) (3)
在屏幕上打印 ((3) 元素 [myList v])▶
length of list#
The length of list block returns the number of items in a list.
([myList v] 长度 :: list)
Parameter |
Description |
|---|---|
variable |
The list variable to return the length of. Users can select an existing list, rename it, or delete it. |
Example
当开始
[Display how many items are in a list.]
设定 [myList v] 为 (1) (2) (3)
在屏幕上打印 ([myList v] 长度 :: list)▶
2D Lists#
2D list item#
The 2D list item block is used to return the value of an item in a 2D list.
((1) 元素 (1)[my2DList v])
Parameter |
Description |
|---|---|
row |
The row of the item (starting at 1). |
column |
The column of the item (starting at 1). |
variable |
The 2D list variable to return an item from. Users can select an existing 2D list, rename it, or delete it. |
Example
当开始
[Display an item from a 2D list.]
设定 [my2DList v] 为 ([1][7]) ([2][8])
在屏幕上打印 ((2) 元素 (2)[my2DList v])▶
replace 2D list item#
The replace 2D list item block updates a specific item in a 2D list.
将 (1) 元素 (1)[my2DList v] 置换为 (1)
Parameter |
Description |
|---|---|
row |
The row index of the item (starting at 1). |
column |
The column index of the item (starting at 1). |
variable |
The 2D list variable containing the item to modify. Users can select an existing 2D list, rename it, or delete it from the drop-down menu. |
value |
The new value assigned to the specified 2D list item. |
Example
当开始
[Replace a value in a 2D list and print the updated item.]
设定 [my2DList v] 为 ([1][2]) ([3][4])
将 (2) 元素 (2)[my2DList v] 置换为 (25)
在屏幕上打印 ((2) 元素 (2)[my2DList v])▶
set 2D list items#
The set 2D list items block sets every item in the 2D list to the entered values.
设定 [my2DList v] 为 ([0][0]) ([0][0])
Parameter |
Description |
|---|---|
variable |
The 2D list variable being assigned values. Users can select an existing 2D list, rename it, or delete it. |
values |
The values to store in the 2D list, entered row by row. |
Example
当开始
[Display an item from a 2D list.]
设定 [my2DList v] 为 ([1][4]) ([2][15])
在屏幕上打印 ((1) 元素 (2)[my2DList v])▶
length of 2D list#
The length of 2D list block reports the number of rows or columns in a 2D list.
([my2DList v] 的 [rows v] 数)
Parameter |
Description |
|---|---|
variable |
The 2D list variable to check the length of. Users can select an existing 2D list, rename it, or delete it. |
rows/columns |
Whether to return the number of rows or column. |
Example
当开始
[Set a 2D list and print the number of rows it has.]
设定 [my2DList v] 为 ([1][5]) ([3][6])
在屏幕上打印 ([my2DList v] 的 [rows v] 数)▶