运算符#

介绍#

The Operator blocks in VEXcode GO 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 — 将数字四舍五入到最接近的整数。

  • 数学函数 — 应用平方根、三角函数、对数和指数运算等运算。

  • 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 block.

数学运算符报告器块。#
([0] [math_plus v] [0])

参数

描述

值 1

运算中使用的第一个数字。

操作员

要使用的数学运算符:

  • + — 加法
  • - — 减法
  • * — 乘法
  • / — 除法

值 2

运算中使用的第二个数字。

例子

当开始 :: hat events
[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

要比较的第二个值。

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[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

要评估的第二个布尔条件。

例子

当开始 :: hat events
[Build Used: Super Code Base 2.0]
[Drive forward and pick up a red or green Disk.]
驱动 [向前 v]
等到 <<辨色仪测得 [红色 v]?> [or v] <辨色仪测得 [绿色 v]?>>
驱动停止
使 [magnet v] 加磁 [boost v]

非运算符#

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.

非运算符布尔块。#
<非 <>>

范围

描述

状况

要反转的布尔条件。

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[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]>

范围

描述

第一操作员

比较运算符:

  • < - 小于
  • ≤ - 小于或等于
  • — 大于
  • ≥ — 大于或等于

价值

要检查的值。

第二操作员

比较运算符:

  • < — 小于
  • ≤ — 小于或等于
  • — 大于
  • ≥ — 大于或等于

例子

当开始 :: hat events
[Build Used: Code Base 2.0]
[Turn and display when facing forward or back. ]
[右 v] 转 [360] 度 ◀ 并且不等待
永久循环
清除所有行
如果 <[270] [math_greater_than v] (底盘归位角度值) [math_greater_than v] [90]> 那么
打印 [Facing backward!] ▶
否则
打印 [Facing forward!] ▶
结束
等待 [1] 秒

随机选择#

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] 之间选随机数

参数

描述

分钟

可以选择的最低可能数字。

最大限度

可以选取的最大数字。

示例

当开始 :: hat events
[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] 位小数)

范围

描述

数字

要舍入的数字。

小数位

要四舍五入的小数位数。

例子

当开始 :: hat events
[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:

  • abs - Absolute value
  • floor - Rounds down
  • ceiling - Rounds up
  • sqrt - Square root
  • sin - Sine
  • cos - Cosine
  • tan - Tangent
  • asin - Inverse sine
  • acos - Inverse cosine
  • atan - Inverse tangent
  • ln - Natural logarithm
  • log - Base 10 logarithm
  • e^ - Euler’s number raised to a power
  • 10^ - 10 raised to a power
  • negative - Reports the negative of the number

数字

应用该函数的数字。

例子

当开始 :: hat events
[Display the square root of 16.]
打印 ([sqrt v] 的 [16]) ▶

#

The remainder reporter block reports the remainder of the division operation between two values.

剩余部分报告器块。#
([0] / [0] 取余)

范围

描述

股利

待除数。

除数

要除以的数字。

例子

当开始 :: hat events
[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

要合并的第二个字符串。

当开始 :: hat events
[Display "VEXcode" on the Console.]
打印 (连接 [VEX] [code]) ▶

#

The letter reporter block reports a single-character string from the specified position in the given string.

快报记者阻拦。#
([apple] 的第 [1] 个字符)

范围

描述

位置

字符串中字符的位置(从 1 开始)。

细绳

要从中提取字母的字符串。

当开始 :: hat events
[Display the first letter of "Robot".]
打印 ([Robot] 的第 (1) 个字符) ▶

长度#

The length reporter block reports the number of characters in the specified string, including spaces.

长度报告块。#
([apple] 长度 :: operators)

范围

描述

细绳

要测量长度的字符串。

例子

当开始 :: hat events
[Count the number of characters in "VEX Robotics".]
打印 ([VEX Robotics] 长度 :: operators) ▶

包含#

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]?>

范围

描述

细绳

要搜索的主字符串。

搜索词

要在字符串中检查的单词或字符。

例子

当开始 :: hat events
[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
[Build Used: Code Base 2.0]
[Display the robot's heading as it turns.]
[右 v] 转
永久循环
清除所有行
打印 (连接 [Currently facing: ] (转换 (底盘归位角度值) 为 [文本 v])) ▶
等待 [0.5] 秒