Broadcasts send messages across all sprites and backdrops in your project. This is an effective way to communicate across sprites and create sequences of events. The broadcast is an Event block that pairs with a Listener block. The sprite sending the message can be completely independent of the sprite receiving the message.
Broadcasting is useful if a script needs to be activated after the start of the program without a user prompt such as a keypress or mouse click.
Listeners listen for messages sent from broadcasts. Broadcasts need to be paired with one or more Listeners. As soon as the listener receives the message from the broadcast, the connected script runs.
Multiple sprites can have the same Listener and independently trigger scripts. This is an effective way to trigger multiple actions across several sprites.
Let’s take a look at example scripts. This first script is the broadcast:
This script is the listener:
When the space key is pressed, the broadcast sends the message “vanish!” across the project. The listener then reacts to this message, triggering an action.