Events#

Introduction#

An event is a starting signal for a set of blocks. Events blocks in VEXcode 123 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.

Below is a list of available blocks:

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 :: hat events

Parameters

Description

This block has no parameters.

Example

  when started :: hat events
  [Drive forward then stop.]
  drive [forward v]    
  wait (2) seconds
  stop driving

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 with the broadcast event and broadcast event and wait blocks.

Example

  when started :: hat events
  [Turn LED green while the robot moves.]
  broadcast [square_drive v]  
  glow [green v]
  when I receive [square_drive v] :: hat events
  [Move in a square pattern.]
  repeat [4]
  drive [forward v] for [100] [mm 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 :: hat events
  [Turn LED green while the robot moves.]
  broadcast [square_drive v]  
  glow [green v]
  when I receive [square_drive v] :: hat events
  [Move in a square pattern.]
  repeat [4]
  drive [forward v] for [100] [mm v]
  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.

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 :: hat events
  [Turn LED green after robot is done moving.]
  broadcast [square_drive v] and wait
  glow [green v]
  when I receive [square_drive v] :: hat events
  [Move in a square pattern.]
  repeat [4]
  drive [forward v] for [100] [mm v]
  turn [right v] for [90] degrees