控件#
介绍#
The Control blocks in VEXcode AIR manage the flow of a project by handling loops, conditions, and delaying blocks from running.
A loop is when a computer repeats the same step or group of steps over and over until it is told to stop. A condition is a rule the computer checks to decide what to do next. For example, the drone can fly forward when a controller button is pressed.
Below is a list of available blocks:
wait — Pauses blocks from running for a specific duration.
wait until — Pauses blocks from running until a specified condition is met.
repeat — Repeats a set of blocks a specific number of times.
forever — Repeats a set of blocks indefinitely.
repeat until — Repeats a set of blocks until a condition is met.
while — Repeats a set of blocks while a condition remains true.
if — Runs a set of blocks if a condition is true.
if / else — 如果条件为真,则运行一组块,否则运行另一组块。
if / else if / else — 根据多种条件运行不同的块集。
break — 立即退出循环。
stop project — Ends the project.
等待#
The wait stack block pauses blocks from running for a specific amount of time before moving to the next block.
等待 (1) 秒
参数 |
描述 |
|---|---|
时间 |
The amount of time to wait, as a positive whole number or decimal in seconds. |
例子
当开始
[Fly for 1 second.]
起飞至 (500) [毫米 v] ▶
等待 [1] 秒
土地 ▶
等到#
The wait until stack block pauses blocks from running until a specified condition is met before moving to the next block.
等到 <>
参数 |
描述 |
|---|---|
状况 |
进入下一个区块前必须满足的条件。如果条件为:
|
例子
当开始
[Hover at 200 mm.]
起飞至 [500] [毫米 v] ▶
爬升 [向下 v]
等到 <(distance [downward v] range in [mm v]) [math_less_than v] [200]>
徘徊
等待 (3) 秒
土地 ▶
重复#
The repeat C block runs the blocks inside it a set number of times.
重复 [10]
结束
参数 |
描述 |
|---|---|
次 |
设置重复块运行次数的整数。 |
例子
当开始
[Move back and forth four times then land.]
起飞至 [500] [毫米 v] ▶
重复 (4)
将 [向前 v] 移至 (500) [毫米 v] ▶
等待 (1) 秒
将 [backward v] 移至 (500) [毫米 v] ▶
等待 (1) 秒
结束
土地 ▶
永远#
The forever C block keeps running the blocks inside it again and again without stopping.
永久循环
结束
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Move with controller.]
起飞至 [500] [毫米 v] ▶
永久循环
使用遥控器移动
结束
重复直到#
The repeat until C block runs the blocks inside it repeatedly while the specified condition is not met.
重复直到 <>
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked before each loop. If it is False, the blocks continue repeating. If it is True, the loop will stop. |
例子
当开始
[Move with controller until button 7 is pressed.]
起飞至 [500] [毫米 v] ▶
重复直到 <遥控器按键 [7 v] 按下了?>
使用遥控器移动
结束
土地 ▶
尽管#
The while C block runs the blocks inside repeatedly while the specified condition is met.
当 <>
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked before each loop. If it is True, the blocks continue repeating. If it is False, the loop will stop. |
例子
当开始
[Hover at 200 mm.]
起飞至 [500] [毫米 v] ▶
当 <(distance [downward v] range in [mm v]) [math_greater_than v] [200]>
爬升 [向下 v]
结束
徘徊
等待 (3) 秒
土地 ▶
如果#
The if C block runs the blocks inside if the condition is True.
如果 <> 那么
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked when the statement runs. If it is True, the blocks inside the if block will run. If it is False, the blocks are skipped over. |
例子
当开始
[Take a picture when button 5 is pressed.]
起飞至 [500] [毫米 v] ▶
永久循环
使用遥控器移动
如果 <遥控器按键 [5 v] 按下了?> 那么
在 [向前 v] 相机上捕捉图像
结束
结束
如果/否则#
The if / else C block determines which set of blocks runs based on whether the condition is True or False.
如果 <> 那么
否则
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked when the statement runs. If it is True, the blocks inside the if block will run. If it is False, it will runs the blocks inside the else block. |
例子
当开始
[Climb when the left joystick is moved up.]
起飞至 [500] [毫米 v] ▶
永久循环
如果 <(控制器轴 [1 v] 位置) [math_greater_than v] [0]> 那么
爬升 [向上 v]
否则
徘徊
结束
如果/否则 如果/否则#
The if / else if / else expandable C block selects which set of blocks runs based on conditions:
if runs its block of code if the condition evaluates as True.
else if checks additional conditions only if all previous conditions evaluated as False. Multiple else if statements can be used.
else runs its block of code only if none of the previous conditions evaluated as True.
如果 <> 那么
否则如果 <> 那么
否则
结束
参数 |
描述 |
|---|---|
状况 |
An expression or variable that is checked when the statement runs. The first condition that is True runs that set of blocks. If all conditions evaluate as False, the blocks inside the else block will run. |
例子
当开始
[Move the drone up or down based on the position of the joystick.]
起飞至 [500] [毫米 v] ▶
永久循环
如果 <(控制器轴 [1 v] 位置) [math_greater_than v] [0]> 那么
移动 [向前 v]
否则如果 <(控制器轴 [1 v] 位置) [math_less_than v] [0]> 那么
移动 [反 v]
否则
徘徊
结束
结束
休息#
The break stack block exits a loop immediately. This block can be used inside repeat, repeat until, while, and forever blocks. Break is useful when a loop needs to stop early based on something that happens during the project, like a button being pressed or a sensor detecting an object.
退出循环
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Land when button 5 is pressed.]
起飞至 [500] [毫米 v] ▶
永久循环
使用遥控器移动
如果 <遥控器按键 [5 v] 按下了?> 那么
退出循环
结束
结束
土地 ▶
停止项目#
The stop project stack block ends a running project.
停止程序 :: control cap
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Stop motors after landing.]
起飞至 [500] [毫米 v] ▶
等待 [1] 秒
土地 ▶
停止程序