Operadores#
Introducción#
The Operator blocks in VEXcode VR 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 block.
([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:
|
valor 2 |
El segundo número utilizado en la operación. |
Ejemplo
cuando empezó
[Perform basic addition and show two decimal places.]
establecer la precisión de impresión a [0.01 v]
imprimir ([10] [math_plus v] [10.5]) ▶
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).
<[0] [math_equal v] [0]>
Parámetro |
Descripción |
|---|---|
valor 1 |
El primer valor a comparar. |
operador |
La comparación a utilizar:
|
valor 2 |
El segundo valor a comparar. |
Ejemplo
cuando empezó
[Turn right until the heading reaches 90 degrees.]
turno [derecha v]
esperar hasta <(rumbo de la unidad en grados) [math_greater_than v] [90]>
deja de conducir
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.
<<> [and v] <>>
Parámetro |
Descripción |
|---|---|
condición 1 |
La primera condición booleana a evaluar. |
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 |
La segunda condición booleana a evaluar. |
Ejemplo
cuando empezó
[Drive until hitting an object or reaching the end of the Playground.]
para siempre
unidad [adelante v]
si <<[DownEye v] detecta [rojo v]?> [or v] <[LeftBumper v] presionado?>> entonces
deja de conducir
fin
fin
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.
<no <>>
Parámetro |
Descripción |
|---|---|
condición |
La condición booleana que se debe invertir. |
Ejemplo
cuando empezó
[Turn until the robot is facing left. ]
para siempre
si <no <(rumbo de la unidad en grados) [math_greater_than v] [270]>> entonces
turno [derecha v]
demás
deja de conducir
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.
<[0] [math_less_than v] [0] [math_less_than v] [0]>
Parámetro |
Descripción |
|---|---|
primer operador |
El operador de comparación a utilizar:
|
valor |
El valor a comprobar. |
segundo operador |
El operador de comparación a utilizar:
|
Ejemplo
cuando empezó
[Turn and display when facing forward or back. ]
girar [derecha v] por [360] grado ◀ y no esperes
para siempre
borrar todas las filas
si <[270] [math_greater_than v] (rumbo de la unidad en grados) [math_greater_than v] [90]> entonces
imprimir [Facing backward!] ▶
demás
imprimir [Facing forward!] ▶
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.
elige al azar de [1] a [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
cuando empezó
[Display a number between 1 and 10.]
imprimir (elige al azar de [1] a [10]) ▶
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.
(redondear de [0] a [0] decimal)
Parámetro |
Descripción |
|---|---|
número |
El número a redondear. |
decimales |
La cantidad de decimales a redondear. |
Ejemplo
cuando empezó
[Display the rounded result of 10 / 3.]
establecer la precisión de impresión a [0.01 v]
imprimir (redondear de ([10] [math_division v] [3]) a [1] decimal) ▶
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.
[abs v] de [0]
Parámetro |
Descripción |
|---|---|
función |
The mathematical operation to apply to the input value:
|
número |
El número al que se aplicará la función. |
Ejemplo
cuando empezó
[Display the square root of 16.]
imprimir ([sqrt v] de [16]) ▶
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 de 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
cuando empezó
[Calculate the angle from current position (4, 3).]
imprimir (atan2 de x:[4] y:[3]) ▶
resto#
The remainder reporter block reports the remainder of the division operation between two values.
(resto de [0]/[0])
Parámetro |
Descripción |
|---|---|
dividendo |
El número a dividir. |
divisor |
El número por el que se dividirá. |
Ejemplo
cuando empezó
[Display the remainder of 10 / 3.]
imprimir (resto de [10]/[3]) ▶
unirse#
The join reporter block reports a single string that combines two input strings.
(unirse [apple] [banana])
parámetro |
descripción |
|---|---|
cadena 1 |
La primera cadena a combinar. |
cadena 2 |
La segunda cadena a combinar. |
cuando empezó
[Display "VEXcode" on the screen.]
imprimir (unirse [VEX] [code]) ▶
carta#
The letter reporter block reports a single-character string from the specified position in the given string.
(letra [1] de [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. |
cuando empezó
[Display the first letter of "Robot".]
imprimir (letra (1) de [Robot]) ▶
longitud#
The length reporter block reports the number of characters in the specified string, including spaces.
(longitud de [apple])
parámetro |
descripción |
|---|---|
cadena |
La cuerda para medir la longitud de. |
Ejemplo
cuando empezó
[Count the number of characters in "VEX Robotics".]
imprimir (longitud de [VEX Robotics]) ▶
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.
<[apple] contiene [a]?>
parámetro |
descripción |
|---|---|
cadena |
La cadena principal dentro de la cual se realizará la búsqueda. |
término de búsqueda |
La palabra o carácter que se debe buscar dentro de la cadena. |
Ejemplo
cuando empezó
[Check if "robotics" contains "bot".]
si <[robotics] contiene [bot]?> entonces
imprimir [The word contains "bot".] ▶
demás
imprimir [Not found.] ▶
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.
(convertir [0] a [texto v])
parámetro |
descripción |
|---|---|
valor |
El número a convertir. |
tipo |
El tipo en el que se convertirá el número:
|
Ejemplo
cuando empezó
[Display the heading.]
imprimir (unirse [Heading: ] (convertir (rumbo de la unidad en grados) a [texto v])) ▶