Events#

Introduction#

The Events blocks in VEXcode 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 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 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 timer#

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

The when timer hat block.#
当计时器> [1] 秒

Parameters

Description

time

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

Example

当计时器> [2] 秒
[Move the 6-Axis Arm after 2 seconds.]
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶

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

Parameters

Description

This block has no parameters.

Example

当开始
[Move the 6-Axis Arm 100 millimeters along the x-axis.]
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶

Parameters

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]

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

当开始
[Move the 6-Axis Arm 100 millimeters along the y-axis.]
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶
广播 [move_y v]

当我收到 [move_y v]
在控制台上打印 [Received!]◀ 并设定光标为下一行
[手臂 v] 位置递增x:[0] y:[100] z:[0] [毫米 v] ▶

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]

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

当开始
[Move the 6-Axis Arm 100 millimeters along the y-axis.]
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶
广播 [move_y v]

当我收到 [move_y v]
在控制台上打印 [Received!]◀ 并设定光标为下一行
[手臂 v] 位置递增x:[0] y:[100] z:[0] [毫米 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] 并等待

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

当开始
[Move the 6-Axis Arm 100 millimeters along the y-axis.]
[手臂 v] 位置递增x:[100] y:[0] z:[0] [毫米 v] ▶
广播 [move_y v] 并等待
在控制台上打印 [Finished moving!]◀ 并设定光标为下一行


当我收到 [move_y v]
在控制台上打印 [Received!]◀ 并设定光标为下一行
[手臂 v] 位置递增x:[0] y:[100] z:[0] [毫米 v] ▶