Uso de eventos#

Events let separate stacks of blocks in a project communicate with each other, using blocks from the Logic - Events category. Blocks whose names begin with broadcast signal that an event has happened, and blocks whose names begin with when run their attached stack of blocks in response.

Broadcast an Event#

Add a Broadcast Block#

Add a broadcast block or a broadcast and wait block to your project.

Screenshot of the Logic - Events toolbox category, with the broadcast and broadcast and wait blocks highlighted.

Choose or Create the Event#

Select the dropdown on the broadcast block to choose an existing event, or to create, rename, or delete an event.

Screenshot of the broadcast block's dropdown open, showing the my_event option along with New event, Rename event, and Delete the "my_event" event options.

Receive the Event#

Add a when I receive Block#

Add a when I receive block to the workspace, and set its dropdown to match the event name used in your broadcast block. Then, attach blocks below it as those blocks will run whenever that event is broadcast.

Screenshot of the Logic - Events toolbox category, with the when started and when I receive blocks highlighted.

Blocks starting with when can also be found with other device categories, running their attached blocks whenever that device’s condition is met. For example, the when Brain button and when Bumper blocks.

The when Brain button hat block.#
cuando Brain [◀ v] botón [presionado v]
The when Bumper hat block.#
cuando [Bumper1 v] [presionado v]

Use Events in a Project#

Once a when I receive block matches the event name used by a broadcast block, running the project lets both stacks run at the same time. For example, this project turns until the Brain’s Check button is pressed, then broadcasts an event that stops the robot from driving.

When started, turns until the Check button is pressed, then broadcasts an event that stops the robot when it’s received.#
cuando inicie
girar [derecha v]
esperar hasta <¿botón [Verificar v] del Brain presionado?>
transmitir [my_event v]
cuando reciba [my_event v]
detener conducción