Events#

Introduction#

The Events blocks in VEXcode AIM allow for event-driven coding, enabling different parts of a project to run in response to triggers such as project start, received events, or user interactions. Below is a list of available blocks:

when started#

The when started block runs its stack when the project begins. You can have multiple when started blocks to run multiple stacks of blocks at once.

The When started hat block.#
    when started :: hat events

parameter

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 block starts a stack when a matching event is broadcast. You can have multiple when I receive event blocks to run multiple stacks of blocks at once.

The When I receive event hat block.#
    when I receive [my_event v]

parameter

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
  [Move forward and turn at the same time.]
  wait until <screen pressed?>
  broadcast [movement v] and wait
  when I receive [movement v]
  move [forward v] for [50] [mm v] ▶
  when I receive [movement v]
  turn [right v] for [90] degrees ▶

broadcast event#

The broadcast event block triggers any matching when I receive event hat block. It does not pause the execution of the stack and continues running the next block immediately.

The Broadcast event stack block.#
    broadcast [my_event v]

parameter

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
  [Display a surprised emoji when the screen is pressed.]
  forever
  if <screen pressed?> then
  broadcast [emoji_press v]
  else
  show [emoji_happy v] looking [forward v]
  when I receive [emoji_press v]
  show [emoji_shocked v] looking [forward v]

broadcast event and wait#

The broadcast event and wait block triggers an event, then pauses execution of the current stack until all triggered when I receive event block stacks have completed.

The Broadcast event and wait stack block.#
    broadcast [my_event v] and wait

parameter

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
  [Move after the screen is pressed.]
  wait until <screen pressed?>
  broadcast [forward_and_turn v] and wait
  print [Movement done.] on screen ▶
  when I receive [forward_and_turn v]
  move [forward v] for [50] [mm v] ▶
  turn [right v] for [90] degrees ▶