Operadores#

Introducción#

The Operator blocks in VEXcode AIM 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.

A continuación se muestra una lista de bloques disponibles:

  • operador matemático – Realiza suma, resta, multiplicación o división.

  • comparison operator – Compares two values using greater than, less than, or equal to operators.

  • operador lógico – Evalúa múltiples condiciones usando y o o.

  • operador no – Invierte un valor booleano.

  • operador de rango – Comprueba si un número cae dentro de un rango.

  • pick random – Genera un número aleatorio dentro de un rango especificado.

  • número redondo – Redondea un número al número entero más cercano.

  • funciones matemáticas – Aplica operaciones como raíz cuadrada, trigonometría, logaritmos y exponenciación.

  • atan2 – Calcula la tangente inversa de y/x.

  • remainder – Reports the remainder of a division operation.

  • join – Combina dos cadenas en una.

  • letra – Extrae un carácter de una cadena por posición.

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

  • contiene – Comprueba si una cadena incluye una palabra o carácter específico.

  • convert – Convierte un número en texto, un número entero o un decimal.

operador matemático#

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 on screen or set print precision on console blocks.

El bloque de reporte del operador matemático.#
([0] [math_plus v] [0])

Parámetros

Descripción

valor 1

El primer número utilizado en la operación.

operador

El operador matemático a utilizar:

  • + - Suma
  • - - Resta
  • * - Multiplicación
  • / - División

valor 2

El segundo número utilizado en la operación.

Ejemplo

when started
[Perform basic addition and show two decimal places.]
set print precision to [0.01 v] on screen
print ([10] [math_plus v] [10.5]) on screen ▶

operador de comparación#

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

El bloque booleano del operador de comparación.#
<[0] [math_equal v] [0]>

Parámetro

Descripción

valor 1

El primer valor a comparar.

operador

La comparación a utilizar:

  • = - Igual a
  • < - Menor que
  • - Menor o igual a
  • > - Mayor que
  • - Mayor o igual a

valor 2

El segundo valor a comparar.

Ejemplo

when started
[Turn right until the heading reaches 90 degrees.]
turn [right v]
wait [0.05] seconds
wait until <(heading in degrees) [math_greater_than v] [90]>
stop all movement

operador lógico#

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.

El bloque booleano del operador lógico.#
<<> [and v] <>>

Parámetro

Descripción

condición 1

The first Boolean condition to check.

operador

The logical operator to use: and reports True if both conditions are True. or reports True if at least one condition is True.

condición 2

The second Boolean condition to check.

Ejemplo

when started
[Kick a held sports ball when the screen is pressed.]
forever
if <<has [sports ball v]?> [and v] <screen pressed?>> then
kick object [hard v]

no operador#

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.

El bloque booleano del operador Not.#
<not <>>

Parámetro

Descripción

condición

La condición booleana que se debe invertir.

Ejemplo

when started
[Turn until a sports ball or barrel is detected.]
forever
get [all cargo v] data from AI Vision
if <not <AI Vision object exists?>> then
turn [right v]
else
stop all movement

operador de rango#

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.

El bloque booleano del operador de rango.#
<[0] [math_less_than v] [0] [math_less_than v] [0]>

Parámetro

Descripción

primer operador

El operador de comparación a utilizar:

  • < - Menor que
  • ≤ - Menor o igual que
  • - Mayor que
  • ≥ - Mayor o igual que

valor

El valor a comprobar.

segundo operador

El operador de comparación a utilizar:

  • < - Menor que
  • ≤ - Menor o igual que
  • - Mayor que
  • ≥ - Mayor o igual que

Ejemplo

when started
[Move forward and report when out of bounds.]
move [forward v] for [100] [mm v] ◀ and don't wait
forever
clear screen
set cursor to row [1] column [1] on screen
if <[25] [math_less_than v] ([y v] position in [mm v]) [math_less_than v] [75]> then
print [In Bounds.] on screen ▶
else
print [Out of Bounds!] on screen ▶

elige al azar#

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.

El bloque de reportero Pick Random.#
pick random [1] to [10]

Parámetros

Descripción

mín.

El número más bajo posible que se puede elegir.

máximo

El número más alto que se puede elegir.

Ejemplos

when started
[Display a number between 1 and 10.]
print (pick random [1] to [10]) on screen ▶

when started
[Display a decimal number between 1 and 10.5.]
set print precision to [All Digits v] on screen
print (pick random [1] to [10.5]) on screen ▶

número redondo#

The round number reporter block reports the given number rounded to the nearest whole number, following standard rounding rules:

  • Si el decimal es 0,5 o mayor, el número se redondea hacia arriba.

  • Si el decimal es menor que 0,5, el número se redondea hacia abajo.

El bloque de reporteros de Número Redondo.#
(round [0] to [0] decimal places)

Parámetro

Descripción

número

El número a redondear.

decimales

La cantidad de decimales a redondear.

Ejemplo

when started
[Display the rounded result of 10 / 3.]
set print precision to [0.01 v] on screen
print (round ([10] [math_division v] [3]) to [1] decimal places) on screen ▶

funciones matemáticas#

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.

El bloque de reportero de funciones matemáticas.#
[abs v] of [0]

Parámetro

Descripción

función

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

número

El número al que se aplicará la función.

Ejemplo

when started
[Display the square root of 16.]
print ([sqrt v] of [16]) on screen ▶

atan2#

The atan2 reporter block reports 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 of x:[4] y:[3])

Parámetro

Descripción

incógnita

La posición horizontal del punto, medida desde el origen (0,0).

y

La posición vertical del punto, medida desde el origen (0,0).

Ejemplo

when started
[Calculate the angle from current position (4, 3).]
print (atan2 of x:[4] y:[3]) on screen ▶

resto#

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

El bloque de reporteros Resto.#
(remainder of [0] / [0])

Parámetro

Descripción

dividendo

El número a dividir.

divisor

El número por el que se dividirá.

Ejemplo

when started
[Display the remainder of 10 / 3.]
print (remainder of [10] / [3]) on screen ▶

unirse#

The join reporter block reports a single string that combines two input strings.

El bloque de reportero Join.#
(join [apple] [banana])

parámetro

descripción

cadena 1

La primera cadena a combinar.

cuerda 2

La segunda cadena a combinar.

when started
[Display "VEXcode" on the screen.]
print (join [VEX] [code]) on screen ▶

carta#

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

El bloque del reportero de Letter.#
(letter [1] of [apple])

parámetro

descripción

posición

La posición del carácter en la cadena (comenzando en 1).

cadena

La cadena de la que se extraerá una letra.

when started
[Display the first letter of "Robot".]
print (letter (1) of [Robot]) on screen ▶

longitud#

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

El bloque reportero de longitud.#
(length of [apple])

parámetro

descripción

cadena

La cuerda para medir la longitud de.

Ejemplo

when started
[Count the number of characters in "VEX Robotics".]
print (length of [VEX Robotics]) on screen ▶

contiene#

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.

El bloque Contiene Booleano.#
<[apple] contains [a]?>

parámetro

descripción

cadena

La cadena principal donde buscar dentro.

término de búsqueda

La palabra o carácter que se debe buscar dentro de la cadena.

Ejemplo

when started
[Check if "robotics" contains "bot".]
if <[robotics] contains [bot]?> then
print [The word contains "bot".] on screen ▶
else
print [Not found.] on screen ▶
fin

convertir#

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.

El bloque de reportero Convert.#
(convert [0] to [text v])

parámetro

descripción

valor

El número a convertir.

tipo

The type to convert the number into: text converts the value to a string, and number converts the value to a decimal.

Ejemplo

when started
[Add any number to 5.]
ask [Give me a number.] and wait
print ((convert (answer) to [number v]) [math_plus v] [5]) on screen ▶