变量#
介绍#
The Variable blocks in VEXcode V5 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 V5, 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.]
设定 [myBoolean v] 为 <true v>
如果 <myBoolean> 那么
在屏幕上打印 [Boolean is True!]▶
结束
设置布尔变量#
The set Boolean variable stack block assigns a True or False value to a Boolean variable.
设定 [myBoolean v] 为 <true v>
范围 |
描述 |
|---|---|
多变的 |
要赋值的布尔变量。用户可以选择现有变量、重命名或删除它。 |
价值 |
A Boolean value (True or 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 4.]
设定 [myList v] 为 (5) (1) (9)
将 [myList v] 元素 (1) 置换为 (1)
在屏幕上打印 ([myList 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.]
设定 [myList v] 为 (1) (2) (3)
在屏幕上打印 ([myList 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.]
设定 [myList v] 为 (1) (2) (3)
在屏幕上打印 ([myList v] 长度 :: list)▶
二维列表#
二维列表项#
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.]
设定 [my2DList v] 为 ([1][7]) ([2][8])
在屏幕上打印 ([my2DList 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.]
设定 [my2DList v] 为 ([1][2]) ([3][4])
将 (25) 元素 (2)(2) 置换为 [my2DList v]
在屏幕上打印 ([my2DList 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.]
设定 [my2DList v] 为 ([1][4]) ([2][15])
在屏幕上打印 ([my2DList 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.]
设定 [my2DList v] 为 ([1][5]) ([3][6])
在屏幕上打印 ([my2DList v] 的 [rows v] 数)▶