Operators#

Introduction#

The Operators blocks in VEXcode AIR 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 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.

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 for screen or Console.

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

Parameters

Description

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.

Example

Perform basic addition and show two decimal places.#
cuando empezó
[Perform basic addition and show two decimal places.]
Establezca la precisión de impresión en [0.01 v] en la consola
imprimir ([10] [math_plus v] [10.5]) en la consola ▶

comparison operator#

The comparison operator block compares two values using a selected operator and returns either 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]>

Parameter

Description

value 1

The first value to compare.

operator

The comparison to use:

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

value 2

The second value to compare.

Example

cuando empezó
[Fly to position (0, 300, 500).]
despegar a [500] [mm v] ▶
esperar (1) segundos
movimiento [adelante v]
esperar hasta <([y v] posición en [mm v]) [math_greater_than v] [300]>
esperar (1) segundos
tierra ▶

logical operator#

The logical operator block checks multiple conditions and returns either True or False based on the selected operator.

  • True — The logic condition is met.

  • False — The logic condition is not met.

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

Parameter

Description

condition 1

The first Boolean condition to evaluate.

operator

The logical operator to use:

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

condition 2

The second Boolean condition to evaluate.

Example

cuando empezó
[Display when buttons 5 and 7 are pressed together.]
esperar hasta <<¿Botón del controlador [5 v] presionado?> [and v] <¿Botón del controlador [7 v] presionado?>>
imprimir [Both buttons pressed!] en la consola ▶

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.

The Not Operator Boolean block.#
<no <>>

Parameter

Description

condition

The Boolean condition to be inverted.

Example

cuando empezó
[Move with controller while button 5 is not pressed.]
despegar a [500] [mm v] ▶
mientras <no <¿Botón del controlador [5 v] presionado?>>
moverse con el controlador
fin
tierra ▶

range operator#

The range operator block checks if a value falls within a specified range. It returns either True or False.

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

Parameter

Description

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

Example

cuando empezó
[Hover at approximately 1000mm then land.]
despegar a [500] [mm v] ▶
subir [arriba v]
esperar hasta <[1000] [math_less_than v] (altitude in [mm v]) [math_less_than v] [1100]>
flotar
esperar (3) segundos
tierra ▶

pick random#

The pick random block generates a random number within a specified range. The number returned will be an integer if both parameters are whole numbers or a decimal if either parameter contains a decimal.

The Pick Random reporter block.#
elige al azar de [1] a [10]

Parameters

Description

min

The lowest possible number that can be picked.

max

The highest possible number that can be picked.

Examples

Display a number between 1 and 10.#
cuando empezó
[Display a number between 1 and 10.]
imprimir (elige al azar de [1] a [10]) en la consola ▶

Display a decimal number between 1 and 10.5.#
cuando empezó
[Display a decimal number between 1 and 10.5.]
Establezca la precisión de impresión en [All Digits v] en la consola
imprimir (elige al azar de [1] a [10.5]) en la consola ▶

round number#

The round number block rounds a given number to the nearest whole number. It follows 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.

The Round Number reporter block.#
(redondear de [0] a [0] decimal)

Parameter

Description

number

The number to round.

decimal places

The amount of decimals places to round to.

Example

Display the rounded result of 10 / 3.#
cuando empezó
[Display the rounded result of 10 / 3.]
Establezca la precisión de impresión en [0.01 v] en la consola
imprimir (redondear de ([10] [math_division v] [3]) a [1] decimal) en la consola ▶

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.

The Math Functions reporter block.#
[abs v] de [0]

Parameter

Description

function

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

number

The number to apply the function to.

Example

Display the square root of 16.#
cuando empezó
[Display the square root of 16.]
imprimir ([sqrt v] de [16]) en la consola ▶

atan2#

The atan2 block calculates the principal value of the inverse tangent of Y/X. It returns the angle in degrees between the positive X-axis and the point (X, Y).

atan2 block#
(atan2 of 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

Calculate the angle from current position (4, 3).#
cuando empezó
[Calculate the angle from current position (4, 3).]
imprimir (atan2 of x:[4] y:[3]) en la consola ▶

remainder#

The remainder block calculates the remainder when dividing one number by another.

The Remainder reporter block.#
remainder of [0] / [0]

Parameter

Description

dividend

The number to be divided.

divisor

The number to divide by.

Example

Display the remainder of 10 / 3.#
cuando empezó
[Display the remainder of 10 / 3.]
imprimir (remainder of [10] / [3]) en la consola ▶

join#

The join block combines two or more strings into a single string. It returns a string that contains the combined text of the given inputs.

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

parameter

description

string 1

The first string to combine.

string 2

The second string to combine.

Example

cuando empezó
[Display "VEXcode" on the Console.]
imprimir (unirse [VEX] [code]) en la consola ▶

letter#

The letter block extracts a specific character from a string based on its position. It returns a single-character string, representing the letter at the given position.

The Letter reporter block.#
(letra [1] de [apple])

parameter

description

position

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

string

The string to extract a letter from.

Example

cuando empezó
[Display the first letter of "drone".]
imprimir (letra (1) de [drone]) en la consola ▶

length#

The length block reports the number of characters in a string, including spaces. It returns a whole number, representing the total number of characters.

The Length reporter block.#
(longitud de [apple])

parameter

description

string

The string to measure the length of.

Example

cuando empezó
[Count the number of characters in "VEX Robotics".]
imprimir (longitud de [VEX Robotics]) en la consola ▶

contains#

The contains block checks if a string includes a specific word or character. It returns either True or False.

  • 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] contains [a] ?>

parameter

description

string

The main string to search within.

search term

The word or character to check for inside the string.

Example

cuando empezó
[Check if "robotics" contains "bot".]
si <[robotics] contains [bot] ?> entonces
imprimir [The word contains "bot".] en la consola ▶
demás
imprimir [Not found.] en la consola ▶
fin

convert#

The convert block changes a number into a different format: a string or decimal number. It returns the value in the selected format:

  • 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.#
(convertir [0] a [texto v])

parameter

description

value

The number to convert.

type

The type to convert the number into:

  • text
  • number

Example

cuando empezó
[Add any number to 5.]
Pregunta [Give me a number.] y espera
imprimir ((convertir (respuesta) a [número v]) [math_plus v] [5]) en la consola ▶