变量#
介绍#
The Variable blocks in VEXcode GO let you store information that your project can use later. A variable is like a labeled container that holds a value, such as a number, a Boolean, or a list of items.
You would use a variable when you want your project to remember something while it is running. For example, a variable could keep track of how many times the robot has moved, how many objects it has counted, or whether a goal has been reached.
Variables are helpful when the information in a project might change. Instead of writing the same number or answer in many places, you can store it in a variable and update it as the project runs. This makes your project easier to change, check, and understand.
In VEXcode GO, Variable blocks can store different kinds of information, including numbers, Boolean values such as true or false, lists, and 2D lists. These blocks are useful when a project needs to count, make decisions, track progress, or organize information.
以下是可用块的列表:
数值变量——存储和修改数字。
numeric variable — Reports the value of a numeric variable.
设置数值变量 — 为数值变量赋值。
更改数值变量 — 将数值变量增加或减少一个设定的值。
布尔变量——存储真或假值。
Boolean variable — Reports the value of a Boolean variable.
设置布尔变量 — 将 True 或 False 值赋给布尔变量。
列表——存储和管理值的集合。
list item — Reports a value from a list based on its position.
替换列表项 — 更新列表中的特定项。
设置列表项 — 为列表赋值。
length of list — Reports the number of items in a list.
二维列表——以网格形式存储和管理值集合。
2D list item — Reports a value from a specific row and column in a 2D list.
替换二维列表项 — 更新二维列表中的特定项。
设置二维列表项 — 为二维列表赋值。
length of 2D list — Reports the number of rows or columns in a 2D list.
数值变量#
数值变量#
The numeric variable reporter block reports the numeric value assigned to the variable.
(myVariable)
范围 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Display the value of the variable.]
设定 [deliveries v] 为 [2]
打印 (deliveries) ▶
设置数值变量#
The set numeric variable stack block assigns a value to a numeric variable.
设定 [myVariable v] 为 [1]
范围 |
描述 |
|---|---|
多变的 |
要赋值的数字变量。用户可以选择现有变量、重命名或删除它。 |
价值 |
分配给变量的数字(可以是整数、小数或数字块)。 |
例子
当开始
[Display the value of the variable.]
设定 [deliveries v] 为 [2]
打印 (deliveries) ▶
改变数值变量#
The change numeric variable stack block increases or decreases a variable’s value by a given amount.
将 [myVariable v] 改变 (1)
范围 |
描述 |
|---|---|
多变的 |
要修改的数字变量。用户可以选择现有变量、重命名或删除它。 |
价值 |
增加或减少变量的量。 |
例子
当开始
[Deliver a package twice.]
设定 [deliveries v] 为 [0]
驱动 [向前 v] [100] [毫米 v] ▶
将 [deliveries v] 改变 [1]
驱动 [向前 v] [100] [毫米 v] ▶
将 [deliveries v] 改变 [1]
打印 (deliveries) ▶
布尔变量#
布尔变量#
The Boolean variable Boolean block reports either a True or False value.
<myBoolean>
范围 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Display a message if the variable is set to True.]
设定 [my_boolean v] 为 <true v>
如果 <my_boolean> 那么
打印 [Boolean is True!] ▶
结束
设置布尔变量#
The set Boolean variable stack block assigns a True or False value to a Boolean variable.
设定 [myBoolean v] 为 <true v>
范围 |
描述 |
|---|---|
多变的 |
要赋值的布尔变量。用户可以选择现有变量、重命名或删除它。 |
价值 |
布尔值(True 或 False)。 |
例子
当开始
[Repeat until 3 deliveries are made.]
设定 [finished v] 为 <false v>
设定 [deliveries v] 为 [0]
重复直到 <finished>
驱动 [向前 v] [100] [毫米 v] ▶
将 [deliveries v] 改变 [1]
如果 <(deliveries) [math_equal v] [3]> 那么
设定 [finished v] 为 <true v>
列表#
列表项#
The list item reporter block reports the value of an item in a list. A list is a variable that can store multiple variables of the same type.
([myList v] 元素 (1))
范围 |
描述 |
|---|---|
指数 |
列表中项目的位置(从 1 开始)。 |
多变的 |
The list variable to report an item from. Users can select an existing list, rename it, or delete it. |
例子
当开始
[Display the delivery locations.]
设定 [delivery_spots v] 为 [Red House] [Green House] [Blue House]
驱动 [向前 v] (100) [毫米 v] ▶
打印 ([delivery_spots v] 元素 (1)) ▶
驱动 [向前 v] (100) [毫米 v] ▶
打印 ([delivery_spots v] 元素 (2)) ▶
驱动 [向前 v] (100) [毫米 v] ▶
打印 ([delivery_spots v] 元素 (3)) ▶
替换列表项#
The replace list item stack block updates a specific item in a list.
将 [myList v] 元素 (1) 置换为 (1)
范围 |
描述 |
|---|---|
多变的 |
包含要修改的项目的列表变量。用户可以选择现有列表、重命名或删除它。 |
指数 |
列表中项目的位置(从 1 开始)。 |
价值 |
分配给指定列表项的新值。 |
例子
当开始
[Replace the first item in a list with "Robot".]
设定 [my_list v] 为 [Red] [Green] [Blue]
将 [my_list v] 元素 (1) 置换为 (1)
打印 ([my_list v] 元素 (1)) ▶
设置列表项#
The set list items stack block sets every item in the list to the entered values.
设定 [myList v] 为 (0) (0) (0)
范围 |
描述 |
|---|---|
多变的 |
正在分配值的列表变量。用户可以选择现有列表、重命名或删除它。 |
价值观 |
要存储在列表中的值,作为单独的项目输入。 |
例子
当开始
[Display the last item in a list.]
设定 [my_list v] 为 [Red] [Green] [Blue]
在屏幕上打印 ([my_list v] 元素 (3))▶
列表长度#
The length of list reporter block reports the number of items in a list.
([myList v] 长度 :: list)
范围 |
描述 |
|---|---|
多变的 |
The list variable to report the length of. Users can select an existing list, rename it, or delete it. |
例子
当开始
[Display how many items are in a list.]
设定 [my_list v] 为 [Red] [Green] [Blue]
在屏幕上打印 ([my_list v] 长度)▶
二维列表#
二维列表项#
The 2D list item reporter block reports the value of an item in a 2D list. 2D lists are variables that store multiple list variables.
([my2DList v] 元素 (1)(1))
范围 |
描述 |
|---|---|
排 |
项目的行(从 1 开始)。 |
柱子 |
项目的列(从 1 开始)。 |
多变的 |
The 2D list variable to report an item from. Users can select an existing 2D list, rename it, or delete it. |
例子
当开始
[Display an item from a 2D list.]
设定 [my_2d_list v] 为 ([1][Red]) ([2] [Green])
打印 ([my_2d_list v] 元素 (2)(2)) ▶
替换二维列表项#
The replace 2D list item stack block updates a specific item in a 2D list.
将 (1) 元素 (1)(1) 置换为 [my2DList v]
范围 |
描述 |
|---|---|
排 |
项目的行索引(从 1 开始)。 |
柱子 |
项目的列索引(从 1 开始)。 |
多变的 |
包含要修改的项目的二维列表变量。用户可以从下拉菜单中选择现有的二维列表、重命名或删除它。 |
价值 |
分配给指定二维列表项的新值。 |
例子
当开始
[Replace a value in a 2D list and print the updated item.]
设定 [my_2d_list v] 为 ([1][Red]) ([2] [Green])
将 [Blue] 元素 [2][2] 置换为 [my_2d_list v]
打印 ([my_2d_list v] 元素 (2)(2)) ▶
设置二维列表项#
The set 2D list items stack block sets every item in the 2D list to the entered values.
设定 [my2DList v] 为 ([0][0]) ([0][0])
范围 |
描述 |
|---|---|
多变的 |
正在赋值的二维列表变量。用户可以选择现有的二维列表,重命名或删除它。 |
价值观 |
逐行输入存储在二维列表中的值。 |
例子
当开始
[Display an item from a 2D list.]
设定 [my_2d_list v] 为 ([1][Red]) ([2] [Green])
在屏幕上打印 ([my_2d_list v] 元素 (1)(2))▶
二维列表的长度#
The length of 2D list reporter block reports the number of rows or columns in a 2D list.
([my2DList v] 的 [rows v] 数)
范围 |
描述 |
|---|---|
多变的 |
要检查长度的二维列表变量。用户可以选择一个现有的二维列表,重命名或删除它。 |
行/列 |
Whether to report the number of rows or columns. |
例子
当开始
[Set a 2D list and print the number of rows it has.]
设定 [my_2d_list v] 为 ([1][Red]) ([2] [Green])
打印 ([my_2d_list v] 的 [rows v] 数) ▶