运算符#

介绍#

The Operators blocks in VEXcode IQ (2nd gen) handle mathematical calculations and string manipulations. These blocks allow for performing arithmetic, evaluating conditions, and processing text.

Below is a list of available blocks:

Math – Perform calculations and evaluate numerical conditions.

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

Strings – Manipulate and analyze text.

  • join – Combines two strings into one.

  • letter – Extracts a character from a string by position.

  • length – Returns the number of characters in a string.

  • contains – Checks if a string includes a specific word or character.

  • convert – Converts a number into text, a whole number, or a decimal.

Math#

math operator#

The math operator block performs basic arithmetic on the values placed on either side. 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.

The Math operator reporter block.#
([0] [math_plus v] [0])

参数

描述

value 1

The first number used in the operation.

operator

The mathematical operator to use:

  • + - Addition
  • - - Subtraction
  • * - Multiplication
  • / - Division

value 2

The second number used in the operation.

例子

当开始 :: hat events
[Perform basic addition and show two decimal places.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 ([10] [math_plus v] [10.5])▶

comparison operator#

The comparison operator block returns a Boolean indicating 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).

The Comparison operator Boolean block.#
<[0] [math_equal v] [0]>

范围

描述

value 1

要比较的第一个值。

operator

The comparison to use:

  • = - Equal to
  • < - Less than
  • - Less than or equal to
  • > - Greater than
  • - Greater than or equal to

value 2

要比较的第二个值。

例子

当开始 :: hat events
[Turn right until the heading reaches 90 degrees.]
[右 v] 转
等待 [0.5] 秒
等到 <(底盘归位角度值) [math_greater_than v] [90]>
驱动停止

logical operator#

The logical operator block returns a Boolean indicating whether the logical condition between multiple values is true or false.

  • True – The logic condition is met.

  • False – The logic condition is not met.

The Logical Operator Boolean block.#
<<> [and v] <>>

范围

描述

条件 1

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

operator

The logical operator to use:

  • and - Returns True if both conditions are True.
  • or - Returns True if at least one condition is True.

条件 2

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

例子

当开始 :: hat events
[Display if the left and right buttons are pressed.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <<Brain [左 v] 键按下了?> [and v] <Brain [右 v] 键按下了?>> 那么
在屏幕上打印 [Buttons pressed!]▶
结束
结束

非运算符#

非运算符 块用于对布尔块的结果进行取反。如果输入为 True,则返回 False;如果输入为 False,则返回 True。

  • True – 输入条件通常会返回 False。

  • False – 输入条件通常会返回 True。

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

范围

描述

状况

要反转的布尔条件。

例子

当开始 :: hat events
[Turn until the robot is facing left. ]
永久循环
如果 <非 <(底盘归位角度值) [math_greater_than v] [270]>> 那么
[右 v] 转
否则
驱动停止

range operator#

The range operator block returns a Boolean indicating whether a value falls within a specified range.

  • True – If the value is within the range.

  • False – If the value is outside the range.

The Range Operator Boolean block.#
<[0] [math_less_than v] [0] [math_less_than v] [0]>

范围

描述

first operator

The comparison operator to use:

  • < - Less than
  • ≤ - Less than or equal to
  • > - Greater than
  • ≥ - Greater than or equal to

value

The value to check.

second operator

The comparison operator to use:

  • < - Less than
  • ≤ - Less than or equal to
  • > - Greater than
  • ≥ - Greater than or equal to

例子

当开始 :: hat events
[Turn and display when facing forward or back. ]
[右 v] 转 [360] 度 ◀ 并且不等待
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[270] [math_greater_than v] (底盘归位角度值) [math_greater_than v] [90]> 那么
在屏幕上打印 [Facing backward!]▶
否则
在屏幕上打印 [Facing forward!]▶

随机选择#

The pick random block returns a random integer within the specified range.

随机挑选记者区块。#
在 [1] 到 [10] 之间选随机数

参数

描述

分钟

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

最大限度

可以选取的最大数字。

示例

当开始 :: hat events
[Display a number between 1 and 10.]
打印 (在 [1] 到 [10] 之间选随机数) ▶

整数#

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]

范围

描述

功能

对输入值应用的数学运算:

  • abs - 绝对值
  • floor - 向下舍入
  • ceiling - 向上舍入
  • sqrt - 平方根
  • sin - 正弦
  • cos - 余弦
  • tan - 正切
  • asin - 反正弦
  • acos - 反余弦
  • atan - 反正切
  • ln - 自然对数
  • log - 以 10 为底的对数
  • e^ - 欧拉数的幂
  • 10^ - 10 的幂
  • negative - 返回数字的负数

数字

应用该函数的数字。

例子

当开始 :: 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])▶

Strings#

join#

The join block returns a single string that combines two or more input strings.

The Join reporter block.#
(连接 [apple] [banana])

parameter

description

string 1

The first string to combine.

string 2

The second string to combine.

当开始 :: hat events
[Display "VEXcode" on the screen.]
在屏幕上打印 (连接 [VEX] [code])▶

letter#

The letter returns a single-character string from the specified position in the given string.

The Letter reporter block.#
([1] 的第 [apple] 个字符)

parameter

description

position

The position of the character in the string (starting at 1).

string

The string to extract a letter from.

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

length#

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

The Length reporter block.#
([apple] 长度 :: operators)

parameter

description

string

The string to measure the length of.

例子

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

contains#

The contains block returns a Boolean indicating 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.

The Contains Boolean block.#
<[apple] 包含 [a]?>

parameter

description

string

The main string to search within.

search term

The word or character to check for inside the string.

例子

当开始 :: hat events
[Check if "robotics" contains "bot".]
如果 <[robotics] 包含 [bot]?> 那么
在屏幕上打印 [The word contains "bot".]▶
否则
在屏幕上打印 [Not found.]▶
结束

convert#

The convert block returns 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 (floating-point) value.

The Convert reporter block.#
(转换 [0] 为 [文本 v])

parameter

description

value

The number to convert.

type

The type to convert the number into:

  • text
  • number

例子

Example coming soon.