Operadores#
Introducción#
The Operators blocks in VEXcode IQ (2nd gen) 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])
Parámetros |
Descripción |
---|---|
value 1 |
The first number used in the operation. |
operator |
The mathematical operator to use:
|
value 2 |
The second number used in the operation. |
Ejemplo
cuando empezó :: hat events
[Perform basic addition and show two decimal places.]
Establezca la precisión de impresión en [0.01 v] en la pantalla
imprimir ([10] [math_plus v] [10.5]) en la pantalla ▶
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]>
Parámetro |
Descripción |
---|---|
value 1 |
El primer valor a comparar. |
operator |
The comparison to use:
|
value 2 |
El segundo valor a comparar. |
Ejemplo
cuando empezó :: hat events
[Turn right until the heading reaches 90 degrees.]
turno [derecha v]
esperar [0.5] segundos
esperar hasta <(rumbo de la unidad en grados) [math_greater_than v] [90]>
deja de conducir
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] <>>
Parámetro |
Descripción |
---|---|
condición 1 |
La primera condición booleana a evaluar. |
operator |
The logical operator to use:
|
condición 2 |
La segunda condición booleana a evaluar. |
Ejemplo
cuando empezó :: hat events
[Display if the left and right buttons are pressed.]
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <<¿Botón del cerebro [izquierda v] presionado?> [and v] <¿Botón del cerebro [derecha v] presionado?>> entonces
imprimir [Buttons pressed!] en la pantalla ▶
fin
fin
no operador#
El bloque operador not invierte el resultado de un bloque booleano. Si la entrada es Verdadero, devuelve Falso; si la entrada es Falso, devuelve Verdadero.
Verdadero: la condición de entrada normalmente devolvería Falso.
Falso: la condición de entrada normalmente devolvería Verdadero.
<no <>>
Parámetro |
Descripción |
---|---|
condición |
La condición booleana que se debe invertir. |
Ejemplo
cuando empezó :: hat events
[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
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]>
Parámetro |
Descripción |
---|---|
first operator |
The comparison operator to use:
|
value |
The value to check. |
second operator |
The comparison operator to use:
|
Ejemplo
cuando empezó :: hat events
[Turn and display when facing forward or back. ]
girar [derecha v] por [360] grado ◀ y no esperes
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <[270] [math_greater_than v] (rumbo de la unidad en grados) [math_greater_than v] [90]> entonces
imprimir [Facing backward!] en la pantalla ▶
demás
imprimir [Facing forward!] en la pantalla ▶
elige al azar#
The pick random block returns a random integer within the specified range.
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ó :: hat events
[Display a number between 1 and 10.]
imprimir (elige al azar de [1] a [10]) ▶
número redondo#
El bloque número redondeado devuelve el número dado redondeado al número entero más cercano, siguiendo las reglas de redondeo estándar:
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ó :: hat events
[Display the rounded result of 10 / 3.]
Establezca la precisión de impresión en [0.01 v] en la pantalla
imprimir (redondear de ([10] [math_division v] [3]) a [1] decimal) en la pantalla ▶
funciones matemáticas#
El bloque funciones matemáticas aplica una función matemática seleccionada a un número dado y devuelve el resultado. Admite operaciones como valor absoluto, redondeo, raíz cuadrada, funciones trigonométricas, logaritmos y exponenciación.
[abdominales v] de [0]
Parámetro |
Descripción |
---|---|
función |
La operación matemática a aplicar al valor de entrada:
|
número |
El número al que se aplicará la función. |
Ejemplo
cuando empezó :: hat events
[Display the square root of 16.]
imprimir ([raíz cuadrada v] de [16]) en la pantalla ▶
atan2#
El bloque atan2 devuelve la tangente inversa de Y/X como un ángulo en grados, que representa el ángulo entre el eje X positivo y el punto (X, Y).
(atan2 of x:[4] y:[3])
Parámetro |
Descripción |
---|---|
x |
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ó :: hat events
[Calculate the angle from current position (4, 3).]
imprimir (atan2 of x:[4] y:[3]) en la pantalla ▶
resto#
El bloque resto devuelve el resto de la operación de división entre dos valores.
(remainder of [0] / [0])
Parámetro |
Descripción |
---|---|
dividendo |
El número a dividir. |
divisor |
El número por el que se dividirá. |
Ejemplo
cuando empezó :: hat events
[Display the remainder of 10 / 3.]
imprimir (remainder of [10] / [3]) en la pantalla ▶
Strings#
join#
The join block returns a single string that combines two or more input strings.
(unirse [apple] [banana])
parameter |
description |
---|---|
string 1 |
The first string to combine. |
string 2 |
The second string to combine. |
cuando empezó :: hat events
[Display "VEXcode" on the screen.]
imprimir (unirse [VEX] [code]) en la pantalla ▶
letter#
The letter returns a single-character string from the specified position in the given string.
(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. |
cuando empezó :: hat events
[Display the first letter of "Robot".]
imprimir (letra (1) de [Robot]) en la pantalla ▶
length#
The length block returns the number of characters in the specified string, including spaces.
(longitud de [apple] :: operators)
parameter |
description |
---|---|
string |
The string to measure the length of. |
Ejemplo
cuando empezó :: hat events
[Count the number of characters in "VEX Robotics".]
imprimir (longitud de [VEX Robotics] :: operators) en la pantalla ▶
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] contiene [a]?>
parameter |
description |
---|---|
string |
The main string to search within. |
search term |
The word or character to check for inside the string. |
Ejemplo
cuando empezó :: hat events
[Check if "robotics" contains "bot".]
si <[robotics] contiene [bot]?> entonces
imprimir [The word contains "bot".] en la pantalla ▶
demás
imprimir [Not found.] en la pantalla ▶
fin
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.
(convertir [0] a [texto v])
parameter |
description |
---|---|
value |
The number to convert. |
type |
The type to convert the number into:
|
Ejemplo
Example coming soon.