Events#
Introduction#
The Events blocks in VEXcode 123 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 – Executes 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 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.
当开始 :: hat events
parameter |
description |
|---|---|
This block has no parameters. |
Example
当开始 :: hat events
[Drive forward then stop.]
驱动 [向前 v]
等待 (2) 秒
驱动停止
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.
当我收到 [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
当开始 :: hat events
[Turn LED green while the robot moves.]
广播 [square_drive v]
发光 [绿色 v]
当我收到 [square_drive v] :: hat events
[Move in a square pattern.]
重复 [4]
驱动 [向前 v] [100] [毫米 v]
[右 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.
广播 [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
当开始 :: hat events
[Turn LED green while the robot moves.]
广播 [square_drive v]
发光 [绿色 v]
当我收到 [square_drive v] :: hat events
[Move in a square pattern.]
重复 [4]
驱动 [向前 v] [100] [毫米 v]
[右 v] 转 [90] 度
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.
广播 [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
当开始 :: hat events
[Turn LED green after robot is done moving.]
广播 [square_drive v] 并等待
发光 [绿色 v]
当我收到 [square_drive v] :: hat events
[Move in a square pattern.]
重复 [4]
驱动 [向前 v] [100] [毫米 v]
[右 v] 转 [90] 度