Events#
Introduction#
An event is a starting signal for a set of blocks. Events blocks in VEXcode VR let different sets of blocks begin at different times. For example, one set of blocks can start when the project begins, and another can start when a signal is sent from somewhere else in the project.
when started – Runs the attached stack of blocks when the project starts.
when I receive event – Runs the attached stack of blocks when a specific event is broadcast.
broadcast event – Triggers an event without pausing other blocks.
broadcast event and wait – Triggers an event and pauses other blocks until the event’s tasks complete.
when started#
The when started hat block starts running the blocks below it when the project begins. Every project needs at least one when started block — without it, the blocks below it will not run. Multiple when started blocks can be used to run different sets of blocks at the same time.
when started :: hat events
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Turn around at the start of the project.]
turn to heading [180] degrees ▶
when I receive event#
The when I receive event hat block starts running the blocks below it when a signal with the same event name is broadcast.
when I receive [my_event v]
Parameters |
Description |
|---|---|
event |
The event to be triggered. Users can select an existing event, create a new one, rename the selected event, or delete it. |
Example
when started :: hat events
[Broadcast after 3 seconds have passed.]
wait until <(timer in seconds) [math_greater_than v] [3]>
broadcast [turn v]
when I receive [turn v]
[When received, print a message and turn right.]
print [Received!] ▶
turn [right v] for [90] degrees ▶
broadcast event#
The broadcast event stack block sends a signal that starts any when I receive event block with the same event name. The rest of the blocks in the project keep running without waiting for those blocks to finish.
broadcast [message1 v]
Parameters |
Description |
|---|---|
event |
The event to trigger. Users can select an existing event, create a new one, rename the selected event, or delete it. |
Example
when started :: hat events
[Broadcast after 3 seconds have passed.]
wait until <(timer in seconds) [math_greater_than v] [3]>
broadcast [turn v]
when I receive [turn v]
[When received, print a message and turn right.]
print [Received!] ▶
turn [right v] for [90] degrees ▶
broadcast event and wait#
The broadcast event and wait stack block sends a signal that starts any when I receive event block with the same event name. The rest of the project will wait for the broadcasted event to finish running.
broadcast [message1 v] and wait
Parameters |
Description |
|---|---|
event |
The event to trigger. Users can select an existing event, create a new one, rename the selected event, or delete it. |
Example
when started :: hat events
[Broadcast after 3 seconds have passed.]
wait until <(timer in seconds) [math_greater_than v] [3]>
broadcast [forward_and_turn v] and wait
print [Movement done.] ▶
when I receive [forward_and_turn v]
[When received, drive forward and turn right.]
drive [forward v] for [100] [mm v] ▶
turn [right v] for [90] degrees ▶