Events#

Introduction#

An event is a starting signal for a set of blocks. Events blocks in VEXcode IQ (2nd gen) 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#

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
  [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.

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
  [Display a message and turn at the same time.]
  wait until <Brain [Check v] button pressed?>
  broadcast [turn v]
  when I receive [turn v]
  print [Received!] on [Brain v] ▶
  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.

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
  [Play a sound when a button is pressed while turning.]
  forever
  if <Brain [Left v] button pressed?> then
  broadcast [button_press v]
  else
  turn [right v]
  when I receive [button_press v]
  play sound [alarm 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 after the Brain's Check button is pressed.]
  wait until <Brain [Check v] button pressed?>
  broadcast [forward_and_turn v] and wait
  print [Movement done.] on [Brain v] ▶
  when I receive [forward_and_turn v]
  drive [forward v] for [100] [mm v] ▶
  turn [right v] for [90] degrees ▶