事件#
简介#
An event is a starting signal for a set of blocks. Events blocks in VEXcode AIM 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.
when started – Runs the attached stack of blocks when the project starts.
when I receive event – Runs the attached stack of blocks when a specific event is broadcast.
broadcast event – Triggers an event without pausing other blocks.
broadcast event and wait – Triggers an event and pauses other blocks until the event’s tasks complete.
当开始#
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.
when started
参数 |
描述 |
|---|---|
该指令块没有参数。 |
示例
when started
[Turn around at the start of the project.]
turn to heading [180] degrees ▶
当我收到事件#
The when I receive event hat block starts running the blocks below it when a signal with the same event name is broadcast.
when I receive [my_event v]
参数 |
描述 |
|---|---|
事件 |
将要触发的事件。用户可以选择一个现有事件、创建新事件、重命名选定事件或将其删除。 |
示例
when started
[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 ▶
广播事件#
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.
broadcast [my_event v]
参数 |
描述 |
|---|---|
事件 |
将要触发的事件。用户可以选择一个现有事件、创建新事件、重命名选定事件或将其删除。 |
示例
when started
[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]
广播事件并等待#
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.
broadcast [my_event v] and wait
参数 |
描述 |
|---|---|
事件 |
将要触发的事件。用户可以选择一个现有事件、创建新事件、重命名选定事件或将其删除。 |
示例
when started
[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 ▶