Events#

When Started#

The When Started block is used to run the attached stack of blocks when the project is started.

A yellow rectangular shape with rounded corners containing the white text "when started".

A when started event will run when the project is started from the start button in VEXcode.

All new projects will automatically include a when started block.

In this example, the When Started block is used to start the project. When the start button is selected, the robot will drive forward, turn right, and drive forward again.

A visual programming interface showing a yellow "when started" block connected to three blue command blocks. The first block reads "drive forward for 200 mm", the second "turn right for 90 degrees", and the third "drive forward for 200 mm". The blocks are interlocked to represent a sequence of instructions.

When Bumper#

The When Bumper block is used to run the attached stack of blocks when the selected Bumper Switch sensor is pressed or released.

A yellow notched block labeled 'when BumperB pressed.'"

Choose which Bumper to use.

A yellow notched block labeled 'when BumperB pressed' with a dropdown menu open showing 'BumperB' selected.

Select which action will trigger the event - pressed or released.

A yellow notched block labeled 'when BumperB pressed' with a dropdown menu open showing 'pressed' selected, and 'released' as an option.

In this example, when the Bumper Switch sensor is pressed, a message will be printed on the Brain.

A yellow notched block labeled 'when BumperB pressed' connected to a purple notched block that says 'print Bumper has been pressed on Brain and set cursor to next row.'"

When Touch LED#

The When Touch LED block is used to run the selected VEX IQ Touch LED is pressed or released.

A yellow notched block labeled 'when TouchLED11 pressed' with dropdown menus for selecting the sensor and the action.

Choose which Touch LED to use.

A yellow notched block labeled 'when TouchLED11 pressed' with a dropdown menu expanded to show the selected option 'TouchLED11' under the sensor selection.

Select which action will trigger the event - pressed or released.

A yellow notched block labeled 'when TouchLED11 pressed' with a dropdown menu expanded to show options 'pressed' and 'released,' with 'pressed' selected.

In this example, when the Touch LED is pressed, a message will be printed on the Brain.

A yellow notched block labeled 'when TouchLED11 pressed' connected to a purple block that says 'print Touch LED was pressed on Brain and set cursor to next row.'"

When Controller Button#

The When Controller Button block is used to run the attached stack of blocks when the selected IQ (1st gen) Controller Button is pressed or released.

A yellow notched block labeled 'when Controller button E Up pressed.'"

Choose which IQ (1st gen) Controller Button to use.

A yellow notched block labeled 'when Controller button E Up pressed' with a dropdown menu expanded, showing various button options such as 'E Up,' 'E Down,' 'F Up,' 'F Down,' 'L Up,' 'L Down,' 'R Up,' and 'R Down,' with 'E Up' selected.

Select which action will trigger the event block: pressed or released.

A yellow notched block labeled 'when Controller button E Up pressed' with a dropdown menu expanded, showing options 'pressed' and 'released,' with 'pressed' selected.

In this example, pressing the R Up Button on the IQ (1st gen) Controller will print a message to the Brain’s screen.

A yellow notched block labeled 'when Controller button R Up pressed' connected to a purple notched block that prints the message 'R Up button was pressed!' on the Brain display and sets the cursor to the next row.

When Controller Axis#

The When Controller Axis block is used to run the attached stack of blocks when the selected IQ (1st gen) Controller joystick axis is moved.

A yellow notched block labeled 'when Controller axis A is changed' with a dropdown menu to select the controller axis.

Choose which IQ (1st gen) Controller joystick axis to use.

A yellow notched block labeled 'when Controller axis A is changed,' with a dropdown menu open, showing options A, B, C, and D, with A selected.

In this example, moving the D joystick axis on the IQ (1st gen) Controller will print a message.

A yellow notched block labeled 'when Controller axis D is changed' connected to a purple notched block labeled 'print Axis D has changed. on Brain and set cursor to next row.'"

When Brain Button#

The When Brain Button block is used to run the attached stack of blocks when the selected IQ (1st gen) Brain Button is pressed or released.

A yellow notched block labeled 'when Brain Up button pressed.'"

Choose which IQ (1st gen) Brain Button to use.

A yellow notched block labeled 'when Brain Up button pressed' with a dropdown menu open under 'Up,' showing options 'Up,' 'Down,' and 'Check.'"

Select which action will trigger the event block: pressed or released.

A yellow notched block labeled 'when Brain Left button pressed' with a dropdown menu open under 'pressed,' showing options 'pressed' and 'released.'"

In this example, pressing the right Brain Button will print a message to the Brain’s screen.

A block of code featuring a yellow notched block labeled 'when Brain Right button pressed' connected to a purple block labeled 'print Right Brain Button was pressed. on Brain and set cursor to next row.'"

When Timer#

The When Timer block is used to run the attached stack of blocks when the Brain’s timer is equal to the given value.

A yellow notched block labeled 'when timer > 1 seconds' with a white oval-shaped input field containing the number 1.

The Brain’s timer begins at the beginning of each project or whenever the Brain’s timer is reset.

Choose an amount of time. The when timer event will run once the Brain’s timer is equal to the entered amount.

A yellow notched block labeled 'when timer > 3.25 seconds' with a white oval-shaped input field containing the number 3.25.

In this example, after 5 seconds have passed, the robot will print the message to the Print Console.

A stack of blocks with a yellow notched block labeled 'when timer > 5 seconds' connected to a purple notched block labeled 'print 5 seconds have passed.'"

When I Receive#

The When I Receive block is used to run the attached stack of blocks when the selected message is received from a broadcasted message.

A yellow notched block labeled 'when I receive message1' with a dropdown menu set to 'message1.'"

Choose which message to listen for. A new message can also be created.

A yellow notched block labeled 'when I receive message1' with a dropdown menu open showing options 'New message' and 'message1,' with 'message1' selected.

In this example, the code will continuously check if the Left Sensor Bumper was pressed. Once pressed, the When I Recieve block will trigger once the bumper_press message is received.

Two sets of blocks are shown. On the left, there is a yellow 'when started' block connected to a 'forever' loop block. Inside the loop is a blue notched block labeled 'if LeftBumper pressed?' connected to a yellow 'then' block that contains a yellow notched block labeled 'broadcast bumper_press.' On the right, there is a yellow notched block labeled 'when I receive bumper_press' connected to a purple rounded block labeled 'print Bumper has been pressed.'"

Broadcast#

The Broadcast block is used to broadcast a message to activate any stacks that begin with a When I Receive block listening for the broadcasted message.

A yellow notched block labeled 'broadcast message1' with a rounded dropdown menu for selecting the message.

The stack that sends the broadcast will continue to run blocks at the same time as other stacks that receive the broadcasted message.

Choose which message to broadcast. A new message can also be created.

A yellow notched block labeled 'broadcast message1' with a rounded dropdown menu expanded, showing options for 'New message' and 'message1,' with 'message1' selected.

In this example, the code will continuously check if the Left Sensor Bumper was pressed. Once pressed, the Broadcast block will trigger the When I Receive block with the message bumper_press.

Two sets of block code are displayed. On the left, a yellow notched block labeled 'when started' is stacked above an orange 'forever' loop block. Inside the loop, a blue hexagonal block labeled 'if LeftBumper pressed?' is connected to an orange notched block labeled 'broadcast bumper_press.' On the right, a yellow notched block labeled 'when I receive bumper_press' is stacked above a purple rounded block labeled 'print Bumper has been pressed.'"

Broadcast and Wait#

The Broadcast and Wait block is used to broadcast a message to activate any stacks that begin with a When I Receive block listening for the broadcasted message while also pausing the rest of the stack.

This block broadcasts a message to activate any stacks that begin with a when I receive block listening for the broadcasted message while also pausing the rest of the stack.

A yellow notched block labeled 'broadcast message1 and wait' is shown. The block has an oval-shaped dropdown menu labeled 'message1.'"

The stack that sends the broadcast and wait will pause until the other stacks that receive the broadcasted message have completed.

Choose which message to broadcast. A new message can also be created.

A yellow notched block labeled 'broadcast message1' with an oval-shaped dropdown menu set to 'message1.' The dropdown menu is expanded, showing two options: 'New message' and 'message1,' with 'message1' selected.

In this example, the code will continuously check if the Left Sensor Bumper was pressed. Once pressed, the Broadcast and Wait block will trigger the When I Receive block with the message bumper_press. No code underneath the When Started block will execute until everything underneath the bumper_press When I Receive block is finished.

On the left, a yellow script begins with a 'when started' notched block followed by a forever loop. Inside the loop, there's a conditional block that checks if 'LeftBumper' is pressed. If true, it broadcasts a 'bumper_press' message and waits. On the right, a separate script starts with a 'when I receive bumper_press' yellow notched block, followed by a blue block that turns right for 90 degrees.

When Optical Sensor#

The When Optical Sensor block is used to run the attached stack of blocks when the selected Optical Sensor detects or loses an object.

A yellow notched block with the text 'when Optical7 detects an object.' The block is used to trigger actions when the Optical7 sensor detects an object.

Choose an Optical Sensor.

A yellow notched block with a dropdown menu open under 'Optical7' showing that 'Optical7' is selected. The block reads 'when Optical7 detects an object,' indicating a trigger for when the Optical7 sensor detects an object.

Choose whether the When Optical detects/loses event is triggered when the sensor detects an object, or loses an object.

A yellow notched block with a dropdown menu open under 'detects' showing that 'detects' is selected. The block reads 'when Optical7 detects an object,' indicating a trigger for when the Optical7 sensor detects an object. The dropdown menu offers the option to switch to 'loses' instead of 'detects.'"

In this example, once the Optical Sensor has detected an object, a message will be printed to the Brain.

A yellow and purple set of stacked blocks. The yellow notched block reads 'when Optical7 detects an object.' The purple rounded block beneath it reads 'print Optical Sensor has detected an object. on Brain and set cursor to next row.'"