Events#

Introduction#

An event is a starting signal for a set of blocks. Events blocks in VEXcode 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 timer – Runs a stack of blocks after the timer exceeds a specified time.

  • 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 timer#

The when timer hat block runs the attached stack of blocks after a specified amount of time.

The when timer hat block.#
  when timer > [1] seconds

Parameters

Description

time

Specifies the number of seconds before the attached stack of blocks starts. Accepts both whole and decimal numbers.

Example

when timer > [2] seconds
[Move the 6-Axis Arm after 2 seconds.]
increment [arm v] position by x:[100] y:[0] z:[0] [mm v] ▶

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.

The When started hat block.#
    when started

Parameters

Description

This block has no parameters.

Example

when started
[Move the 6-Axis Arm 100 millimeters along the x-axis.]
increment [arm v] position by x:[100] y:[0] z:[0] [mm v] ▶

Parameters

Description

This block has no parameters.

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.

The When I receive event hat block.#
    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
  [Move the 6-Axis Arm 100 millimeters along the y-axis.]
  increment [arm v] position by x:[100] y:[0] z:[0] [mm v] ▶
  broadcast [move_y v]

  when I receive [move_y v]
  print [Received!] on console ◀ and set cursor to next row
  increment [arm v] position by x:[0] y:[100] z:[0] [mm v] ▶

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.

The Broadcast event stack block.#
    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
  [Move the 6-Axis Arm 100 millimeters along the y-axis.]
  increment [arm v] position by x:[100] y:[0] z:[0] [mm v] ▶
  broadcast [move_y v]

  when I receive [move_y v]
  print [Received!] on console ◀ and set cursor to next row
  increment [arm v] position by x:[0] y:[100] z:[0] [mm v] ▶

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.

The Broadcast event and wait stack block.#
    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
  [Move the 6-Axis Arm 100 millimeters along the y-axis.]
  increment [arm v] position by x:[100] y:[0] z:[0] [mm v] ▶
  broadcast [move_y v] and wait
  print [Finished moving!] on console ◀ and set cursor to next row


  when I receive [move_y v]
  print [Received!] on console ◀ and set cursor to next row
  increment [arm v] position by x:[0] y:[100] z:[0] [mm v] ▶