运算符#
Introduction#
The Operators blocks in VEXcode EXP 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.
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.
([0] [math_plus v] [0])
Parameters |
Description |
---|---|
value 1 |
The first number used in the operation. |
operator |
The mathematical operator to use:
|
value 2 |
The second number used in the operation. |
Example
当开始 :: 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).
<[0] [math_equal v] [0]>
Parameter |
Description |
---|---|
value 1 |
The first value to compare. |
operator |
The comparison to use:
|
value 2 |
The second value to compare. |
Example
当开始 :: 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.
<<> [and v] <>>
Parameter |
Description |
---|---|
condition 1 |
The first Boolean condition to evaluate. |
operator |
The logical operator to use:
|
condition 2 |
The second Boolean condition to evaluate. |
Example
当开始 :: hat events
[Display if the left and right buttons are pressed.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
如果 <<Brain [左 v] 键按下了?> [and v] <Brain [右 v] 键按下了?>> 那么
在屏幕上打印 [Buttons pressed!]▶
结束
结束
not operator#
The not operator block inverts the result of a Boolean block. If the input is True, it returns False, and if the input is False, it returns True.
True – The input condition would normally return False.
False – The input condition would normally return True.
<非 <>>
Parameter |
Description |
---|---|
condition |
The Boolean condition to be inverted. |
Example
当开始 :: 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.
<[0] [math_less_than v] [0] [math_less_than v] [0]>
Parameter |
Description |
---|---|
first operator |
The comparison operator to use:
|
value |
The value to check. |
second operator |
The comparison operator to use:
|
Example
当开始 :: 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!]▶
pick random#
The pick random block returns a random integer within the specified range.
在 [1] 到 [10] 之间选随机数
Parameters |
Description |
---|---|
min |
The lowest possible number that can be picked. |
max |
The highest possible number that can be picked. |
Examples
当开始 :: hat events
[Display a number between 1 and 10.]
打印 (在 [1] 到 [10] 之间选随机数) ▶
round number#
The round number block returns the given number rounded to the nearest whole number, following standard rounding rules:
If the decimal is 0.5 or greater, the number rounds up.
If the decimal is less than 0.5, the number rounds down.
([0] 四舍五入到 [0] 位小数)
Parameter |
Description |
---|---|
number |
The number to round. |
decimal places |
The amount of decimals places to round to. |
Example
当开始 :: hat events
[Display the rounded result of 10 / 3.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 (([10] [math_division v] [3]) 四舍五入到 [1] 位小数)▶
math functions#
The math functions 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.
[绝对值 v] 的 [0]
Parameter |
Description |
---|---|
function |
The mathematical operation to apply to the input value:
|
number |
The number to apply the function to. |
Example
当开始 :: hat events
[Display the square root of 16.]
在屏幕上打印 ([平方根 v] 的 [16])▶
atan2#
The atan2 block returns 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])
Parameter |
Description |
---|---|
x |
The horizontal position of the point, measured from the origin (0,0). |
y |
The vertical position of the point, measured from the origin (0,0). |
Example
当开始 :: hat events
[Calculate the angle from current position (4, 3).]
在屏幕上打印 (atan2 x:[4] y:[3])▶
remainder#
The remainder block returns the remainder of the division operation between two values.
(remainder of [0] / [0])
Parameter |
Description |
---|---|
dividend |
The number to be divided. |
divisor |
The number to divide by. |
Example
当开始 :: 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.
(连接 [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 block returns a single-character string from the specified position in the given string.
([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.
([apple] 长度 :: operators)
parameter |
description |
---|---|
string |
The string to measure the length of. |
Example
当开始 :: 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.
<[apple] 包含 [a]?>
parameter |
description |
---|---|
string |
The main string to search within. |
search term |
The word or character to check for inside the string. |
Example
当开始 :: 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.
(转换 [0] 为 [文本 v])
parameter |
description |
---|---|
value |
The number to convert. |
type |
The type to convert the number into:
|
Example
Example coming soon.