Events#

Introduction#

The Events blocks in VEXcode V5 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 – Runs the attached stack of blocks when the project starts.

  • when autonomous – Runs the attached stack of blocks when the Brain recieves an autonomous signal.

  • when driver control – Runs the attached stack of blocks when the Brain recieves a driver control signal.

  • when I receive event – Runs the attached stack when a specific event is broadcast.

  • broadcast event – Triggers an event without pausing execution.

  • broadcast event and wait – Triggers an event and pauses execution until the event’s tasks complete.

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.#
当开始

parameter

description

This block has no parameters.

Example

当开始
[Turn around at the start of the project.]
归位至 [180] 度 ▶

when autonomous#

The when autonomous block runs the attached stack of blocks when the Brain recieves an autonomous signal.

This block is only used for Competition projects.

The When started hat block.#
当自控 :: hat events

parameter

description

This block has no parameters.

when driver control#

The when driver control block runs the attached stack of blocks when the Brain recieves a driver control signal.

This block is only used for Competition projects.

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

parameter

description

This block has no parameters.

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.#
当我收到 [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

当开始
[Display a message and turn at the same time when the screen is pressed.]
等到 <屏幕按下了?>
广播 [turn v]
当我收到 [turn v]
在屏幕上打印 [Received!]▶
[右 v] 转 [90] 度 ▶

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.#
广播 [message1 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

当开始
[Turn left when the screen is pressed.]
永久循环
如果 <屏幕按下了?> 那么
广播 [screen_press v]
否则
[右 v] 转
当我收到 [screen_press v]
[左 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.#
广播 [message1 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

当开始
[Move after the Brain's screen is pressed.]
等到 <屏幕按下了?>
广播 [forward_and_turn v] 并等待
在屏幕上打印 [Movement done.]▶
当我收到 [forward_and_turn v]
驱动 [向前 v] [100] [毫米 v] ▶
[右 v] 转 [90] 度 ▶