运算符#

介绍#

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.

字符串——操作和分析文本。

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

数学#

数学运算符#

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

参数

描述

值 1

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

操作员

The mathematical operator to use:

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

值 2

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

例子

当开始 :: hat events
[执行基本加法并显示两位小数。]
在屏幕上设定打印精度为 [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:

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

值 2

要比较的第二个值。

例子

当开始 :: hat events
[向右转,直到航向达到 90 度.]
[右 v] 转
等待 [0.05] 秒
等到 <(归位角度值) [math_greater_than v] [90]>
停止移动

逻辑运算符#

逻辑运算符块返回一个布尔值,指示多个值之间的逻辑条件是真还是假。

  • 真——逻辑条件满足。

  • False – 逻辑条件不满足。

逻辑运算符布尔块。#
<<> [和 v] <>>

范围

描述

条件 1

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

操作员

要使用

  • 逻辑运算符:
    • and - 如果两个条件都为 True,则返回 True。3
    • or - 如果至少一个条件为 True,
    返回 True。5
  • 条件 2

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

    例子

    当开始 :: hat events
    [按下屏幕时踢手中的运动球。]
    永久循环
    如果 <<[运动球 v] 存在?> [和 v] <屏幕按下了?>> 那么
    [困难 v] 踢出对象
    

    非运算符#

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

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

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

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

    范围

    描述

    状况

    要反转的布尔条件。

    例子

    当开始 :: hat events
    [转动直到检测到运动球或桶。]
    永久循环
    获得 AI 视觉仪 [所有货物 v] 数据
    如果 <非 <AI 视觉仪对象存在?>> 那么
    [右 v] 转
    否则
    停止移动
    

    范围运算符#

    范围运算符块返回一个布尔值,指示某个值是否在指定范围内。

    • True – 如果值在范围内。

    • False – 如果值超出范围。

    范围运算符布尔块。#
    <[0] [math_less_than v] [0] [math_less_than v] [0]>
    

    范围

    描述

    第一操作员

    The comparison operator to use:

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

    价值

    要检查的值。

    第二操作员

    The comparison operator to use:

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

    例子

    当开始 :: hat events
    [越界时向前移动并报告。]
    移动 [正 v] [100] [mm v] ◀ 并且不等待
    永久循环
    清屏
    在屏幕上设定光标至 [1] 行 [1] 列
    如果 <[25] [math_less_than v] ([y v] 位置 [mm v]) [math_less_than v] [75]> 那么
    打印 [在界内。] 在屏幕 ▶
    否则
    打印 [出界!] 在屏幕 ▶
    

    随机选择#

    选择随机块返回指定范围内的随机数,可以是整数或小数。

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

    参数

    描述

    分钟

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

    最大限度

    可以选取的最大数字。

    示例

    当开始 :: hat events
    [显示 1 到 10 之间的数字。]
    打印 (在 [1] 到 [10] 之间选随机数) 在屏幕 ▶
    

    当开始 :: hat events
    [显示 1 至 10.5 之间的十进制数。]
    在屏幕上设定打印精度为 [全部数字 v]
    打印 (在 [1] 到 [10.5] 之间选随机数) 在屏幕 ▶
    

    整数#

    round number 块按照标准舍入规则返回四舍五入到最接近的整数的给定数字:

    • 如果小数为 0.5 或更大,则数字向上舍入。

    • 如果小数小于 0.5,则数字向下舍入。

    整数报告器区块。#
    (四舍五 [0] 入到 [0] 小数位)
    

    范围

    描述

    数字

    要舍入的数字。

    小数位

    要四舍五入的小数位数。

    例子

    当开始 :: hat events
    [显示 10 / 3 的四舍五入结果。]
    在屏幕上设定打印精度为 [0.01 v]
    打印 (四舍五 ([10] [math_division v] [3]) 入到 [1] 小数位) 在屏幕 ▶
    

    数学函数#

    数学函数 模块将选定的数学函数应用于给定数字并返回结果。它支持绝对值、舍入、平方根、三角函数、对数和指数等运算。

    数学函数报告块。#
    [绝对值 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 - Returns the negative of the number

    数字

    应用该函数的数字。

    例子

    当开始 :: hat events
    [显示 16 的平方根。]
    打印 ([平方根 v] 的 [16]) 在屏幕 ▶
    

    反义词#

    atan2 块以度为单位返回 Y/X 的反正切,表示正 X 轴和点 (X, Y) 之间的角度。

    (atan2 of x: [4] y: [3])
    

    范围

    描述

    点的水平位置,从原点 (0,0) 测量。

    点的垂直位置,从原点 (0,0) 测量。

    例子

    当开始 :: hat events
    [计算从当前位置 (4, 3) 的角度。]
    打印 (atan2 of x: [4] y: [3]) 在屏幕 ▶
    

    #

    remainder 块返回两个值之间的除法运算的余数。

    剩余部分报告器块。#
    剩余的 [0] / [0]
    

    范围

    描述

    股利

    待除数。

    除数

    要除以的数字。

    例子

    当开始 :: hat events
    [显示 10 / 3 的余数。]
    打印 (剩余的 [10] / [3]) 在屏幕 ▶
    

    字符串#

    加入#

    join 块返回一个由两个或多个输入字符串组合而成的字符串。

    加入记者区块。#
    (加入 [apple] [banana])
    

    范围

    描述

    字符串 1

    第一个要合并的字符串。

    字符串 2

    要合并的第二个字符串。

    当开始 :: hat events
    [屏幕上显示“VEXcode”。]
    打印 (加入 [VEX] [code]) 在屏幕 ▶
    

    #

    字母 从给定字符串中的指定位置返回单字符的字符串。

    快报记者阻拦。#
    (letter [1] of [apple])
    

    范围

    描述

    位置

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

    细绳

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

    当开始 :: hat events
    [显示“Robot”的首字母。]
    打印 (letter (1) of [Robot]) 在屏幕 ▶
    

    长度#

    length 块返回指定字符串中的字符数,包括空格。

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

    范围

    描述

    细绳

    要测量长度的字符串。

    例子

    当开始 :: hat events
    [计算“VEX Robotics”中的字符数。]
    打印 (长度 [VEX Robotics]) 在屏幕 ▶
    

    包含#

    contains 块返回一个布尔值,指示指定的字符串是否包含给定的单词或字符。

    • True – 字符串包含特定的单词或字符。

    • False – 字符串不包含特定的单词或字符。

    包含布尔块。#
    <[apple] 包含 [a] ?>
    

    范围

    描述

    细绳

    要搜索的主字符串。

    搜索词

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

    例子

    当开始 :: hat events
    [检查“robotics”是否包含“bot”。]
    如果 <[robotics] 包含 [bot] ?> 那么
    打印 [该单词包含"bot"。] 在屏幕 ▶
    否则
    打印 [未找到。] 在屏幕 ▶
    结束
    

    转变#

    convert 块返回转换为指定类型的数字值,可以是文本或数字。

    • 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])
    

    范围

    描述

    价值

    要转换的数字。

    类型

    The type to convert the number into:

    • text
    • number

    例子

    当开始 :: hat events
    [将任意数字加到 5 上。]
    询问 [给我一个号码。] 并等待
    打印 ((转换 (答案) 为 [数字 v]) [math_plus v] [5]) 在屏幕 ▶