运算符#
介绍#
VEXcode AIM 中的运算符块用于处理数学计算和字符串操作。这些块可用于执行算术运算、评估条件以及处理文本。以下是可用块的列表:
数学——执行计算并评估数值条件。
math operator – Performs addition, subtraction, multiplication, or division.
comparison operator – Compares two values using greater than, less than, or equal operators.
logical operator – Evaluates multiple conditions using and or or.
not operator – Inverts a Boolean value.
range operator – Checks if a number falls within a range.
pick random – Generates a random number within a specified range.
round number – Rounds a number to the nearest whole number.
math functions – Applies operations such as square root, trigonometry, logarithms, and exponentiation.
atan2 – Computes the inverse tangent of y/x.
remainder – Returns the remainder of a division operation.
字符串——操作和分析文本。
数学#
数学运算符#
数学运算符 块对放置在两侧的值执行基本算术运算。它会根据项目的打印精度返回结果,该精度默认为小数点后 0 位,但可以使用 设置打印精度 块 进行调整。
([0] [math_plus v] [0])
参数 |
描述 |
---|---|
值 1 |
运算中使用的第一个数字。 |
操作员 |
The mathematical operator to use:
|
值 2 |
运算中使用的第二个数字。 |
例子
当开始 :: hat events
[Perform basic addition and show two decimal places.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 ([10] [math_plus v] [10.5])▶
比较运算符#
比较运算符块返回一个布尔值,指示两个值之间的比较是真还是假。
True
– 比较正确(例如,5 > 3 返回 True)。False
– 比较不正确(例如,2 ≥ 5 返回 False)。
<[0] [math_equal v] [0]>
范围 |
描述 |
---|---|
值 1 |
要比较的第一个值。 |
操作员 |
The comparison to use:
|
值 2 |
要比较的第二个值。 |
例子
当开始 :: hat events
[Turn right until the heading reaches 90 degrees.]
[右 v] 转
等待 [0.05] 秒
等到 <(归位角度值) [math_greater_than v] [90]>
停止移动
逻辑运算符#
逻辑运算符块返回一个布尔值,指示多个值之间的逻辑条件是真还是假。
真——逻辑条件满足。
False – 逻辑条件不满足。
<<> [and v] <>>
范围 |
描述 |
---|---|
条件 1 |
要评估的第一个布尔条件。 |
操作员 |
要使用
|
条件 2 |
要评估的第二个布尔条件。 |
例子
当开始 :: hat events
[Kick a held sports ball when the screen is pressed.]
永久循环
如果 <<有 [运动球 v] 吗?> [and v] <屏幕按下了?>> 那么
[大力 v] 踢出对象
非运算符#
非运算符 块用于对布尔块的结果进行取反。如果输入为 True,则返回 False;如果输入为 False,则返回 True。
True – 输入条件通常会返回 False。
False – 输入条件通常会返回 True。
<非 <>>
范围 |
描述 |
---|---|
状况 |
要反转的布尔条件。 |
例子
当开始 :: hat events
[Turn until a sports ball or barrel is detected.]
永久循环
从 AI 视觉仪获取 [所有货物 v] 数据
如果 <非 <AI 视觉仪对象存在?>> 那么
[右 v] 转
否则
停止移动
范围运算符#
范围运算符块返回一个布尔值,指示某个值是否在指定范围内。
True – 如果值在范围内。
False – 如果值超出范围。
<[0] [math_less_than v] [0] [math_less_than v] [0]>
范围 |
描述 |
---|---|
第一操作员 |
要使用的比较运算符:
|
价值 |
要检查的值。 |
第二操作员 |
要使用的比较运算符:
|
例子
当开始 :: hat events
[Move forward and report when out of bounds.]
将 [向前 v] 移至 [100] [毫米 v] ◀ 并且不等待
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[25] [math_less_than v] ([y v] 转位 [毫米 v]) [math_less_than v] [75]> 那么
在屏幕上打印 [In Bounds.]▶
否则
在屏幕上打印 [Out of Bounds!]▶
随机选择#
选择随机块返回指定范围内的随机数,可以是整数或小数。
在 [1] 到 [10] 之间选随机数
参数 |
描述 |
---|---|
分钟 |
可以选择的最低可能数字。 |
最大限度 |
可以选取的最大数字。 |
示例
当开始 :: hat events
[Display a number between 1 and 10.]
在屏幕上打印 (在 [1] 到 [10] 之间选随机数)▶
当开始 :: hat events
[Display a decimal number between 1 and 10.5.]
在屏幕上设定打印精度为 [All Digits v]
在屏幕上打印 (在 [1] 到 [10.5] 之间选随机数)▶
整数#
round number 块按照标准舍入规则返回四舍五入到最接近的整数的给定数字:
如果小数为 0.5 或更大,则数字向上舍入。
如果小数小于 0.5,则数字向下舍入。
([0] 四舍五入到 [0] 位小数)
范围 |
描述 |
---|---|
数字 |
要舍入的数字。 |
小数位 |
要四舍五入的小数位数。 |
例子
当开始 :: hat events
[Display the rounded result of 10 / 3.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 (([10] [math_division v] [3]) 四舍五入到 [1] 位小数)▶
数学函数#
数学函数 模块将选定的数学函数应用于给定数字并返回结果。它支持绝对值、舍入、平方根、三角函数、对数和指数等运算。
[绝对值 v] 的 [0]
范围 |
描述 |
---|---|
功能 |
对输入值应用的数学运算:
|
数字 |
应用该函数的数字。 |
例子
当开始 :: hat events
[Display the square root of 16.]
在屏幕上打印 ([平方根 v] 的 [16])▶
反义词#
atan2 块以度为单位返回 Y/X 的反正切,表示正 X 轴和点 (X, Y) 之间的角度。
(atan2 of x:[4] y:[3])
范围 |
描述 |
---|---|
x |
点的水平位置,从原点 (0,0) 测量。 |
y |
点的垂直位置,从原点 (0,0) 测量。 |
例子
当开始 :: hat events
[Calculate the angle from current position (4, 3).]
在屏幕上打印 (atan2 of x:[4] y:[3])▶
余#
remainder 块返回两个值之间的除法运算的余数。
(remainder of [0] / [0])
范围 |
描述 |
---|---|
股利 |
待除数。 |
除数 |
要除以的数字。 |
例子
当开始 :: hat events
[Display the remainder of 10 / 3.]
在屏幕上打印 (remainder of [10] / [3])▶
字符串#
加入#
join 块返回一个由两个或多个输入字符串组合而成的字符串。
(连接 [apple] [banana])
范围 |
描述 |
---|---|
字符串 1 |
第一个要合并的字符串。 |
字符串 2 |
要合并的第二个字符串。 |
当开始 :: hat events
[Display "VEXcode" on the screen.]
在屏幕上打印 (连接 [VEX] [code])▶
信#
字母 从给定字符串中的指定位置返回单字符的字符串。
([1] 的第 [apple] 个字符)
范围 |
描述 |
---|---|
位置 |
字符串中字符的位置(从 1 开始)。 |
细绳 |
要从中提取字母的字符串。 |
当开始 :: hat events
[Display the first letter of "Robot".]
在屏幕上打印 ((1) 的第 [Robot] 个字符)▶
长度#
length 块返回指定字符串中的字符数,包括空格。
([apple] 长度 :: operators)
范围 |
描述 |
---|---|
细绳 |
要测量长度的字符串。 |
例子
当开始 :: hat events
[Count the number of characters in "VEX Robotics".]
在屏幕上打印 ([VEX Robotics] 长度 :: operators)▶
包含#
contains 块返回一个布尔值,指示指定的字符串是否包含给定的单词或字符。
True
– 字符串包含特定的单词或字符。False
– 字符串不包含特定的单词或字符。
<[apple] 包含 [a]?>
范围 |
描述 |
---|---|
细绳 |
要搜索的主字符串。 |
搜索词 |
要在字符串中检查的单词或字符。 |
例子
当开始 :: hat events
[Check if "robotics" contains "bot".]
如果 <[robotics] 包含 [bot]?> 那么
在屏幕上打印 [The word contains "bot".]▶
否则
在屏幕上打印 [Not found.]▶
结束
转变#
convert 块返回转换为指定类型的数字值,可以是文本或数字。
text – 将数字转换为字符串。数字必须是字符串格式才能与字符串运算符块一起使用。
数字 – 将数字转换为十进制(浮点)值。
(转换 [0] 为 [文本 v])
范围 |
描述 |
---|---|
价值 |
要转换的数字。 |
类型 |
将数字转换为的类型:
|
例子
当开始 :: hat events
[Add any number to 5.]
询问 [Give me a number.] 并等待
在屏幕上打印 ((转换 (answer) 为 [数字 v]) [math_plus v] [5])▶