操作员#
介绍#
The Operator blocks in VEXcode V5 help the robot work with numbers and words. These blocks can solve math problems, compare values, evaluating if conditions are true or false, and working with strings. Strings can be used to print values and words.
以下是可用模块列表:
数学运算符 – 执行加法、减法、乘法或除法。
comparison operator – Compares two values using greater than, less than, or equal to operators.
逻辑运算符 – 使用 and 或 or 来评估多个条件。
非运算符 – 反转布尔值。
范围运算符 – 检查一个数字是否在某个范围内。
pick random – 生成指定范围内的随机数。
round number – 将数字四舍五入到最接近的整数。
数学函数 – 应用平方根、三角函数、对数和指数运算等操作。
atan2 – 计算 y/x 的反正切值。
remainder – Reports the remainder of a division operation.
join – 将两个字符串合并为一个字符串。
letter – 按位置从字符串中提取字符。
length – Reports the number of characters in a string.
contains – 检查字符串是否包含特定单词或字符。
convert – 将数字转换为文本、整数或小数。
数学运算符#
The math operator reporter block performs basic math operations on the values placed on either side of the operator. It returns a result based on the project’s print precision, which defaults to 0 decimal places but can be adjusted using the set print precision on screen or set print precision on console blocks.
([0] [math_plus v] [0])
参数 |
描述 |
|---|---|
值 1 |
运算中使用的第一个数字。 |
操作员 |
使用的数学运算符:
|
值 2 |
运算中使用的第二个数字。 |
例子
当开始
[Perform basic addition and show two decimal places.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 ([10] [math_plus v] [10.5])▶
比较算子#
The comparison operator Boolean block reports whether the comparison between two values is True or False.
True – The comparison is correct (e.g., 5 > 3 returns True).
False – The comparison is incorrect (e.g., 2 ≥ 5 returns False).
<[0] [math_equal v] [0]>
范围 |
描述 |
|---|---|
值 1 |
首先要比较的值。 |
操作员 |
比较规则:
|
值 2 |
第二个要比较的值。 |
例子
当开始
[Turn right until the heading reaches 90 degrees.]
[右 v] 转
等待 [0.5] 秒
等到 <(底盘归位角度值) [math_greater_than v] [90]>
驱动停止
逻辑运算符#
The logical operator Boolean block reports whether the logical condition between multiple values is True or False.
True – The logic condition is met.
False – The logic condition is not met.
<<> [and v] <>>
范围 |
描述 |
|---|---|
条件 1 |
第一个要评估的布尔条件。 |
操作员 |
The logical operator to use: and reports True if both conditions are True. or reports True if at least one condition is True. |
条件 2 |
需要评估的第二个布尔条件。 |
例子
当开始
[Display if the ▼ and B Controller buttons are pressed.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <<[Controller 1 v] [▼ v] 按下?> [and v] <[Controller 1 v] [B v] 按下?>> 那么
在屏幕上打印 [Buttons pressed!]▶
结束
结束
非操作员#
The not operator Boolean block inverts the result of a Boolean block. If the input is True, it reports False, and if the input is False, it reports True.
True – The input condition would normally report False.
False – The input condition would normally report True.
<非 <>>
范围 |
描述 |
|---|---|
状况 |
要取反的布尔条件。 |
例子
当开始
[Turn until the robot is facing left. ]
永久循环
如果 <非 <(底盘归位角度值) [math_greater_than v] [270]>> 那么
[右 v] 转
否则
驱动停止
靶场操作员#
The range operator Boolean block reports whether a value falls within a specified range.
True – If the value is within the range.
False – If the value is outside the range.
<[0] [math_less_than v] [0] [math_less_than v] [0]>
范围 |
描述 |
|---|---|
第一运营商 |
比较运算符:
|
价值 |
要检查的值。 |
第二操作员 |
比较运算符:
|
例子
当开始
[Turn and display when facing forward or back. ]
[右 v] 转 [360] 度 ◀ 并且不等待
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[90] [math_less_than v] (底盘归位角度值) [math_less_than v] [270]> 那么
在屏幕上打印 [Facing backward!]▶
否则
在屏幕上打印 [Facing forward!]▶
随机#
The pick random reporter block reports a random positive or negative number between a minimum and a maximum. It can return both the min value and the max value. For example, picking 1 to 10 can return any whole number from 1 through 10.
在 [1] 到 [10] 之间选随机数
参数 |
描述 |
|---|---|
最小 |
可以选择的最小数字。 |
最大限度 |
可以选择的最大数字。 |
示例
当开始
[Display a number between 1 and 10.]
在屏幕上打印 (在 [1] 到 [10] 之间选随机数)▶
整数#
The round number reporter block reports the given number rounded to the nearest whole number, following standard rounding rules:
如果小数部分是 0.5 或更大,则向上取整。
如果小数部分小于 0.5,则向下取整。
([0] 四舍五入到 [0] 位小数)
范围 |
描述 |
|---|---|
数字 |
要四舍五入的数字。 |
小数位数 |
四舍五入到小数点后的位数。 |
例子
当开始
[Display the rounded result of 10 / 3.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 (([10] [math_division v] [3]) 四舍五入到 [1] 位小数)▶
数学函数#
The math functions reporter block applies a selected mathematical function to a given number and returns the result. It supports operations such as absolute value, rounding, square roots, trigonometric functions, logarithms, and exponentiation.
[abs v] 的 [0]
范围 |
描述 |
|---|---|
功能 |
The mathematical operation to apply to the input value:
|
数字 |
要应用该函数的数字。 |
例子
当开始
[Display the square root of 16.]
在屏幕上打印 ([sqrt v] 的 [16])▶
atan2#
The atan2 reporter block reports the inverse tangent of Y/X as an angle in degrees, representing the angle between the positive X-axis and the point (X, Y).
(atan2 x:[4] y:[3])
范围 |
描述 |
|---|---|
x |
从原点 (0,0) 测量的点的水平位置。 |
是 |
从原点 (0,0) 测量的点的垂直位置。 |
例子
当开始
[Calculate the angle from current position (4, 3).]
在屏幕上打印 (atan2 x:[4] y:[3])▶
余#
The remainder reporter block reports the remainder of the division operation between two values.
([0] / [0] 取余)
范围 |
描述 |
|---|---|
股利 |
待除数。 |
除数 |
要除以的数字。 |
例子
当开始
[Display the remainder of 10 / 3.]
在屏幕上打印 ([10] / [3] 取余)▶
加入#
The join reporter block reports a single string that combines two input strings.
(连接 [apple] [banana])
范围 |
描述 |
|---|---|
字符串 1 |
要合并的第一个字符串。 |
字符串 2 |
第二个要合并的字符串。 |
当开始
[Display "VEXcode" on the screen.]
在屏幕上打印 (连接 [VEX] [code])▶
信#
The letter reporter block reports a single-character string from the specified position in the given string.
([apple] 的第 [1] 个字符)
范围 |
描述 |
|---|---|
位置 |
字符串中字符的位置(从 1 开始)。 |
细绳 |
要从中提取字母的字符串。 |
当开始
[Display the first letter of "Robot".]
在屏幕上打印 ([Robot] 的第 (1) 个字符)▶
长度#
The length reporter block reports the number of characters in the specified string, including spaces.
([apple] 长度)
范围 |
描述 |
|---|---|
细绳 |
用来测量长度的绳子。 |
例子
当开始
[Count the number of characters in "VEX Robotics".]
在屏幕上打印 ([VEX Robotics] 长度)▶
包含#
The contains Boolean block reports whether the specified string includes the given word or character.
True – The string includes that specific word or character.
False – The string does not include that specific word or character.
<[apple] 包含 [a]?>
范围 |
描述 |
|---|---|
细绳 |
要搜索的主字符串。 |
搜索词 |
要检查的字符串中的单词或字符。 |
例子
当开始
[Check if "robotics" contains "bot".]
如果 <[robotics] 包含 [bot]?> 那么
在屏幕上打印 [The word contains "bot".]▶
否则
在屏幕上打印 [Not found.]▶
结束
转变#
The convert reporter block reports the value of a number converted to the specified type, either as text or a number.
text – Converts the number to a string. Numbers must be in string format to work with String Operator blocks.
number – Converts the number to a decimal value.
(转换 [0] 为 [文本 v])
范围 |
描述 |
|---|---|
价值 |
要转换的数字。 |
类型 |
要将数字转换为以下类型:
|
例子
当开始 :: hat events
[Display the robot's heading as it turns.]
[右 v] 转
永久循环
清除所有行
打印 (连接 [Currently facing: ] (转换 (底盘归位角度值) 为 [文本 v])) ▶
等待 [0.5] 秒