Control#

Introducción#

The Control blocks in VEXcode VR manage the flow of a project by handling loops, conditions, and delaying blocks from running.

A loop is when a computer repeats the same step or group of steps over and over until it is told to stop. A condition is a rule the computer checks to decide what to do next. For example, a robot can move forward if a sensor detects an object.

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

  • wait – Pauses blocks from running for a specific duration.

  • wait until – Pauses blocks from running until a specified condition is met.

  • repeat – Repeats a set of blocks a specific number of times.

  • forever – Repeats a set of blocks indefinitely.

  • repeat until – Repeats a set of blocks until a condition is met.

  • while – Repeats a set of blocks while a condition remains true.

  • if – Runs a set of blocks if a condition is true.

  • if / else – Ejecuta un conjunto de bloques si una condición es verdadera, de lo contrario ejecuta otro.

  • if / else if / else – Ejecuta diferentes conjuntos de bloques dependiendo de múltiples condiciones.

  • break – Sale inmediatamente de un bucle repeat, forever, repeat until o while.

  • stop project – Ends the project.

esperar#

The wait stack block pauses blocks from running for a specific amount of time before moving to the next block.

bloque de pila de espera#
esperar (1) segundos

Parámetros

Descripción

tiempo

The amount of time to wait, as a positive whole number or decimal in seconds.

Ejemplo

Cuando se inicia, avanza durante un segundo y luego detiene todo movimiento.#
cuando empezó :: hat events
[Move forward for one second, then stop.]
unidad [adelante v]
esperar (1) segundos
deja de conducir

esperar hasta#

The wait until stack block pauses blocks from running until a specified condition is met before moving to the next block.

esperar hasta que se apile el bloque#
esperar hasta <>

Parámetros

Descripción

condición

La condición que debe cumplirse antes de pasar al siguiente bloque.

Ejemplo

Cuando se inicia, avanza hasta que se presiona la pantalla y luego detiene todo movimiento.#
cuando empezó :: hat events
[Move forward until a button is pressed, then stop.]
unidad [adelante v]
esperar hasta <[LeftBumper v] presionado?>
deja de conducir

repetir#

The repeat C block runs the blocks inside it a set number of times.

repetir bloque c#
repetir [10]
fin

Parámetros

Descripción

veces

Un número entero que establece cuántas veces se ejecuta el bloque repetir.

Ejemplo

cuando empezó :: hat events
[Move in a square path.]
repetir [4]
unidad [adelante v] para [150] [mm v] ▶
girar [derecha v] por [90] grado ▶
fin

para siempre#

The forever C block keeps running the blocks inside it again and again without stopping.

bloque c para siempre#
para siempre
fin

Parámetros

Descripción

Este bloque no tiene parámetros.

Ejemplo

Cuando se inicia, se mueve continuamente en una trayectoria cuadrada avanzando 50 mm y girando 90 grados a la derecha en un bucle infinito.#
cuando empezó :: hat events
[Move in a square path forever.]
para siempre
unidad [adelante v] para [150] [mm v] ▶
girar [derecha v] por [90] grado ▶
fin

repetir hasta#

The repeat until C block runs the blocks inside it repeatedly while the specified condition is not met.

repetir hasta bloquear#
repetir hasta <>
fin

Parámetros

Descripción

condición

An expression or variable that is checked before each loop. If it is False, the blocks continue repeating. If it is True, the loop will stop.

Ejemplo

Cuando se inicia, mantiene todos los LED rojos hasta que se presiona la pantalla y luego los apaga.#
cuando empezó :: hat events
[Move the pen until the bumper is pressed.]
unidad [adelante v]
repetir hasta <[LeftBumper v] presionado?>
mover pluma [abajo v]
esperar (0.5) segundos
mover pluma [arriba v]
esperar (0.5) segundos
fin
esperar (0.5) segundos
deja de conducir

mientras#

The while C block runs the blocks inside repeatedly while the specified condition is met.

mientras que el bloque c#
mientras <>
fin

Parámetros

Descripción

condición

An expression or variable that is checked before each loop. If it is True, the blocks continue repeating. If it is False, the loop will stop.

Ejemplo

Al iniciarse, avanza 200 mm con todos los LED en verde. Los LED se apagan al detenerse el movimiento.#
cuando empezó :: hat events
[Display a message while moving.]
unidad [adelante v] para [300] [mm v] ◀ y no esperes
mientras <¿La unidad se está moviendo?>
imprimir [Moving...] ▶
esperar (0.1) segundos
borrar todas las filas
fin
imprimir [Done!] ▶

si#

The if C block runs the blocks inside if the condition is True.

si bloque#
si <> entonces
fin

Parámetros

Descripción

condición

An expression or variable that is checked when the statement runs. If it is True, the blocks inside the if block will run. If it is False, the blocks are skipped over.

Ejemplo

Al iniciarse, comprueba continuamente si la pantalla está presionada. Si se presiona, el robot patea un objeto con fuerza media.#
cuando empezó :: hat events
[Turn in a circle if the bumper is pressed.]
unidad [adelante v]
para siempre
si <[LeftBumper v] presionado?> entonces
unidad [atrás v] para (200) [mm v] ▶
girar [derecha v] por (360) grado ▶
fin
deja de conducir
fin

si/de lo contrario#

The if / else C block determines which set of blocks runs based on whether the condition is True or False.

si entonces si no bloque#
si <> entonces
demás
fin

Parámetros

Descripción

condición

An expression or variable that is checked when the statement runs. If it is True, the blocks inside the if block will run. If it is False, it will runs the blocks inside the else block.

Ejemplo

Al iniciarse, comprueba continuamente si la pantalla está presionada. Si se presiona, muestra un emoji de emoción mirando hacia adelante; de ​​lo contrario, muestra un emoji de aburrimiento mirando hacia adelante.#
cuando empezó :: hat events
[If bumper pressed, reverse and turn right.]
para siempre
si <[LeftBumper v] presionado?> entonces
unidad [atrás v] para (100) [mm v] ▶
girar [derecha v] por (90) grado ▶
demás
unidad [adelante v]
fin

si/si no si/si no#

The if / else if / else expandable C block selects which set of blocks runs based on conditions:

  • if runs its block of code if the condition evaluates as True.

  • else if checks additional conditions only if all previous conditions evaluated as False. Multiple else if statements can be used.

  • else runs its block of code only if none of the previous conditions evaluated as True.

si no, si no, bloque#
si <> entonces
de lo contrario si <> entonces
demás
fin

Parámetros

Descripción

condición

An expression or variable that is checked when the statement runs. The first condition that is True runs that set of blocks. If all conditions evaluate as False, the blocks inside the else block will run.

Ejemplo

Cuando la posición del eje 1 del controlador cambia, se mueve hacia adelante si se lo empuja hacia adelante, se mueve hacia atrás si se lo tira hacia atrás y se detiene cuando está en punto muerto.#
cuando empezó :: hat events
[Turn right if the an Eye Sensor detects red, left if it detects green, and continue driving if anything else.]
para siempre
si <[FrontEye v] detecta [rojo v]?> entonces
girar [derecha v] por (90) grado ▶
de lo contrario si <[FrontEye v] detecta [verde v]?> entonces
girar [izquierda v] por (90) grado ▶
demás
unidad [adelante v]
fin
fin

romper#

The break stack block exits a loop immediately. This block can be used inside repeat, repeat until, while, and forever blocks. Break is useful when a loop needs to stop early based on something that happens during the project, like a button being pressed or a sensor detecting an object.

romper bloque de pila#
romper

Parámetros

Descripción

Este bloque no tiene parámetros.

Ejemplo

Cuando se inicia, los LED parpadean en rojo y verde cada 0,5 segundos hasta que se presiona la pantalla y luego se detiene.#
cuando empezó :: hat events
[Stop turning after a button is pressed.]
para siempre
unidad [adelante v]
si <[LeftBumper v] presionado?> entonces
romper
fin
fin
deja de conducir

detener el proyecto#

The stop project stack block ends a running project.

detener el bloqueo del proyecto#
detener el proyecto

Parámetros

Descripción

Este bloque no tiene parámetros.

Ejemplo

Cuando se inicia, los LED parpadean en rojo y verde cada 0,5 segundos hasta que se presiona la pantalla, luego se detiene el proyecto.#
cuando empezó :: hat events
[Stop the project entirely after a button is pressed.]
para siempre
unidad [adelante v]
si <[LeftBumper v] presionado?> entonces
detener el proyecto
fin
fin