变量#

介绍#

The Variable blocks in VEXcode AIR 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 drone 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 AIR, 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.

以下是可用块的列表:

数字变量 - 存储和修改数字。

布尔变量——存储 TrueFalse 值。

列表——存储和管理值的集合。

2D 列表——存储和管理网格中的值集合。

数值变量#

数值变量#

The numeric variable reporter block reports the numeric value assigned to the variable.

数值变量报告块。#
(my_variable)

范围

描述

该块没有参数。

例子

当开始
[Use a variable to fly forward and back the same distance.]
设定 [fly_distance v] 为 [90]
起飞至 [500] [毫米 v] ▶
将 [向前 v] 移至 (fly_distance) [毫米 v] ▶
等待 (1) 秒
将 [backward v] 移至 (fly_distance) [毫米 v] ▶
等待 (1) 秒
土地 ▶

设置数值变量#

The set numeric variable stack block assigns a value to a numeric variable.

范围

描述

多变的

要赋值的数字变量。用户可以选择现有变量、重命名或删除它。

价值

分配给变量的数字(可以是整数、小数或数字块)。

例子

当开始
[Set a variable to fly forward and back the same distance.]
设定 [fly_distance v] 为 [90]
起飞至 [500] [毫米 v] ▶
将 [向前 v] 移至 (fly_distance) [毫米 v] ▶
等待 (1) 秒
将 [backward v] 移至 (fly_distance) [毫米 v] ▶
等待 (1) 秒
土地 ▶

更改数值变量#

The change numeric variable stack block increases or decreases a variable’s value by a given amount.

改变数值变量堆栈块。#
将 [my_variable v] 改变 (1)

范围

描述

多变的

要修改的数字变量。用户可以选择现有变量、重命名或删除它。

价值

增加或减少变量的量。

例子

当开始
[Fly forward for 50, 150, and 250mm.]
设定 [fly_distance v] 为 [50]
起飞至 [500] [毫米 v] ▶
重复 (3)
将 [向前 v] 移至 (fly_distance) [毫米 v] ▶
等待 (1) 秒
将 [fly_distance v] 改变 (100)
结束
土地 ▶

布尔变量#

布尔变量#

The Boolean variable Boolean block reports either a True or False value.

布尔变量报告块。#
<my_boolean>

范围

描述

该块没有参数。

例子

当开始
[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.

设置布尔变量堆栈块。#
设定 [my_boolean v] 为 <true v>

范围

描述

多变的

要赋值的布尔变量。用户可以选择现有变量、重命名或删除它。

价值

A Boolean value (True or False).

例子

当开始
[Repeat until 3 deliveries are made.]
起飞至 [500] [毫米 v] ▶
设定 [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.

列表项报告器块。#
([my_list v] 元素 (1))

范围

描述

指数

列表中项目的位置(从 1 开始)。

多变的

用于报告项目的列表变量。用户可以选择现有列表、重命名或删除它。

例子

当开始
[Display the delivery locations.]
起飞至 [500] [毫米 v] ▶
设定 [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.

替换列表项堆栈块。#
将 [my_list v] 元素 (1) 置换为 (1)

范围

描述

多变的

包含要修改的项目的列表变量。用户可以选择现有列表、重命名或删除它。

指数

列表中项目的位置(从 1 开始)。

价值

分配给指定列表项的新值。

例子

当开始
[Replace the first item in a list with "AprilTag".]
设定 [my_list v] 为 [Drone] [Controller] [Headset]
将 [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.

设置列表项堆栈块。#
设定 [my_list 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.

列表长度报告块。#
([my_list v] 长度 :: list)

范围

描述

多变的

要报告长度的列表变量。用户可以选择现有列表、重命名或删除它。

例子

当开始
[Display how many items are in a list.]
设定 [my_list v] 为 [Red] [Green] [Blue]
在屏幕上打印 ([my_list 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.

2D 列表项报告器块。#
([my_2d_list v] 元素 (1)(1))

范围

描述

项目的行(从 1 开始)。

柱子

项目的列(从 1 开始)。

多变的

用于报告项目的二维列表变量。用户可以选择现有的二维列表,对其进行重命名或删除。

例子

当开始
[Display an item from a 2D list.]
设定 [my_2d_list v] 为 ([1][Drone]) ([4][Propeller])
在屏幕上打印 ([my_2d_list v] 元素 (2)(2))▶

替换二维列表项#

The replace 2D list item stack block updates a specific item in a 2D list.

替换 2D 列表项堆栈块。#
将 (1) 元素 (1)(1) 置换为 [my_2d_list v]

范围

描述

项目的行索引(从 1 开始)。

柱子

项目的列索引(从 1 开始)。

多变的

包含要修改的项目的二维列表变量。用户可以从下拉菜单中选择现有的二维列表、重命名或删除它。

价值

分配给指定二维列表项的新值。

例子

当开始
[Replace a value in a 2D list and print the updated item.]
设定 [my_2d_list v] 为 ([1][Drone]) ([4][Propeller])
将 [Headset] 元素 [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.

替换 2D 列表项堆栈块。#
设定 [my_2d_list v] 为 ([0][0]) ([0][0])

范围

描述

多变的

正在赋值的二维列表变量。用户可以选择现有的二维列表,重命名或删除它。

价值观

逐行输入要存储在二维列表中的值。

例子

当开始
[Display an item from a 2D list.]
设定 [my_2d_list v] 为 ([1][Drone]) ([4][Propeller])
在屏幕上打印 ([my_2d_list v] 元素 (1)(2))▶

二维列表的长度#

The length of 2D list reporter block reports the number of rows or columns in a 2D list.

2D 列表报告块的长度。#
([my_2d_list 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][Drone]) ([4][Propeller])
在屏幕上打印 ([my_2d_list v] 的 [rows v] 数)▶