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 VR Blocks.

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.

Diagram illustrating VEXcode VR Blocks for various event triggers including When started, When bumper, and more.

Choose which Bumper to use.

Flowchart illustrating VEXcode VR blocks: When started, When bumper, When timer, When I receive, Broadcast methods.

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

Image illustrating the When bumper" block in VEXcode VR

In this example, when the Bumper Switch sensor is pressed, the robot will stop moving.

Diagram illustrating the use of the When bumper" block in VEXcode VR to stop a robot when the bumper sensor is pressed.

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.

When timer block in VEXcode VR, illustrating its use to run code after a specified time interval.

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.

Image showing the When timer" block in VEXcode VR

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

Diagram illustrating the use of the When timer block in VEXcode VR, showing robot actions after a timer event.

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.

Diagram illustrating the use of the When I receive" block in VEXcode VR for triggering actions based on broadcast messages.

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

VEXcode VR Blocks interface showing the When I receive" block in a programming context for robot actions.

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.

Diagram illustrating VEXcode VR Blocks for event-driven programming with 'When started', 'When bumper', and 'When I receive'.

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.

Illustration of the Broadcast block used in VEXcode VR to send messages for event-driven programming.

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.

Image depicting VEXcode VR Blocks for event handling: When started, When bumper, When timer, and When I receive.

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.

Diagram illustrating VEXcode VR Blocks for event-driven programming with 'When started', 'When bumper', and 'When I receive'.

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.

Diagram illustrating the Broadcast and wait" block in VEXcode VR

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.

Image depicting VEXcode VR Blocks for event handling: When started, When bumper, When timer, and When I receive.

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.

VEXcode VR Blocks event flow diagram illustrating When started, When bumper, When timer, and Broadcast blocks.

When Eye Sensor#

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

When Eye Sensor block in VEXcode VR, used to trigger actions when an object is detected or lost.

The When Eye Sensor event can be used to create actions or behaviors based on whether the Eye Sensor detects an object in range of the sensor or loses an object that was in range of the sensor.

Choose an Eye Sensor.

Diagram illustrating the When Eye Sensor block in VEXcode VR, showing its function in detecting objects.

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

Diagram illustrating the When Eye Sensor block in VEXcode VR, showing actions triggered by object detection.

In this example, once the Down Eye Sensor has detected an object, the VR Robot will print a message to the Print Console.

Image illustrating the When Eye Sensor block in VEXcode VR, showing how it detects objects and triggers actions.