Consica Labs

Consica Labs
Chapter 11

Broadcast Messages

Sending signal flags between sprites

Definition

Broadcast messages are invisible signals sent from one sprite that trigger specific events on other sprites across the project. Key concepts include Hat Block, Sensing Block.

Think of Broadcast Messages as:

Director script
Grid movements
Trigger alarms
Costume racks

Just as an actor changes costume or walks across the theater grid on cue, Broadcast Messages dictates sprite behavior.

Real-Life Example

Just as you coordinate actions in real life, Broadcast Messages works by structuring logic commands in sequence:

  1. 1 Register the trigger event block.
  2. 2 Run calculations or movements within a continuous control block.
  3. 3 Update values or graphics on the stage viewport.

Key Highlights:

  • Trigger event
  • Logic evaluation
  • Visual update

Interactive Diagram

Launch the interactive diagram to see this in action.

Open Interactive Diagram

The interactive diagram for this chapter demonstrates Broadcast Messages. It shows one sprite broadcasting a message and other sprites receiving it and starting their scripts.

What to explore:

  • click to send a broadcast; watch all receiving sprites react; see how messages coordinate multiple sprites
  • broadcasts allow sprites to communicate with each other — one sprite sends a message and others can respond to it

Introduction

In a play, when one actor finishes a scene, the next actor knows to enter because someone signaled them — maybe a doorbell rang, or a character shouted 'Come in!'. In Scratch, sprites communicate the same way using Broadcast Messages. Broadcasts let one sprite send a message that all other sprites (and the stage) can hear and respond to. They are Scratch's way of coordinating actions between multiple characters.

Broadcasts solve an important problem: how do you make multiple sprites do things at the right time? Without broadcasts, you would have to rely on timers or complex condition chains. With broadcasts, any sprite can announce an event — 'Enemy Defeated', 'Level Complete', 'Coin Collected' — and any other sprite can respond by running its own script for that message. This keeps your project organized and modular.

In this chapter, you will learn how to send and receive Broadcast Messages, understand the difference between 'broadcast' and 'broadcast and wait', design communication systems between sprites, and use broadcasts to create coordinated multi-sprite behaviors. By the end, you will be able to orchestrate complex interactions between many sprites.

How It Works

The 'broadcast ()' block sends a message to all sprites and the stage. Any script that starts with 'when I receive ()' for that message will run. The sending sprite does not wait for receivers — it immediately continues to the next block. This is a 'fire and forget' approach. Multiple receivers can respond to the same message simultaneously, each running their own scripts.

The 'broadcast () and wait' block sends a message but pauses the sending sprite until all receiving scripts have finished running. This is useful when you need to ensure a sequence completes before continuing. For example, if you broadcast 'open door' and then want the player to walk through, you should 'broadcast and wait' so the door animation finishes before the player moves.

Household Object Analogy

Think of Broadcast Messages like a school intercom system. The principal (one sprite) makes an announcement over the intercom (broadcast). Every classroom (other sprites) hears the announcement. Some classrooms respond immediately (start a script), others ignore it if it does not apply to them. If the principal says 'wait for a response' (broadcast and wait), they pause until the responding classrooms finish their actions.

Deeper Dive

Broadcast Messages have names that you define. Common message names include 'start game', 'game over', 'next level', 'enemy spawn', 'collect coin', 'open door', 'jump', and 'reset'. Choose descriptive names that clearly indicate what happened. The same message can trigger different responses in different sprites — one sprite might play a sound, another might change costumes, and a third might update a variable.

Broadcasts can chain together. A sprite receives broadcast A and in response sends broadcast B. This creates a sequence of events that can be very powerful. For example: sprite broadcasts 'enemy defeated'. Score sprite receives it and adds points, then broadcasts 'check level complete'. Level sprite receives that, checks if all enemies are gone, and if so broadcasts 'level complete', which triggers the victory animation and level transition.

You can also broadcast to yourself — a sprite can send a broadcast that its own 'when I receive' scripts respond to. This is useful for organizing a sprite's own code into separate, named routines. It is Scratch's equivalent of creating a function or procedure. A script labeled with a descriptive broadcast name is easier to understand than a long sequence of blocks.

Key Insight

Broadcasts are Scratch's implementation of the Observer pattern, a common design pattern in software engineering where objects (observers) subscribe to events and get notified when those events occur. This pattern is used extensively in professional software development, from GUI frameworks to game engines.

Advanced

The order of receiver execution when a broadcast is sent is not guaranteed. Scratch runs receiving scripts in parallel through its interleaving scheduler. If you need a specific order, either use 'broadcast and wait' or design your broadcasts so that the first broadcast triggers the first action, which then sends a second broadcast for the next action, creating a sequential chain.

Multiple broadcasts can be sent in sequence. A sprite might broadcast 'show intro', wait 2 seconds, broadcast 'start gameplay', wait for 'game over' to be received, then broadcast 'show results'. This pattern creates a complete game flow controlled by broadcast-driven state transitions, similar to finite state machines used in professional game development.

Broadcasts can carry no data beyond the message name. If you need to send data with a broadcast (like the amount of damage dealt or the type of power-up collected), combine broadcasts with variables. Set a shared variable before broadcasting, and receivers can read it. For example: set 'damageAmount' to 25, then broadcast 'enemy hit'. The enemy sprite reads 'damageAmount' and subtracts it from its health.

Vocabulary Table

Term Definition
Broadcast MessagesThe primary technological concept explaining how components interact within the context of Scratch Programming.
Coordinate GridThe X and Y plane representing the Stage layout coordinates.
Hat BlockA block with a rounded top that registers events to launch scripts.
Sensing BlockA block that checks for collisions, touch parameters, or mouse pointer coordinates.

Fun Facts

Broadcast Messages are Scratch's most important tool for multi-sprite coordination. Almost any project with more than two sprites uses broadcasts.

There is no limit to how many Broadcast Messages you can create in a project, though using too many can make the project harder to understand.

The 'broadcast and wait' block was added in Scratch 2.0 to give programmers more control over execution order.

A sprite can both send and receive the same broadcast message. This creates a recursive self-call that, while rarely useful, can be used for certain looping patterns.

Broadcasts work even if no sprite is listening — the message is simply ignored. This means you can safely Broadcast Messages that only some sprites respond to.

Common Misconceptions

Misconception: Broadcasts can only be received by sprites, not the stage.

Truth: The stage can also receive broadcasts using 'when I receive'. This is useful for background music changes, backdrop switches, and global game logic.

Misconception: 'Broadcast' and 'broadcast and wait' work identically.

Truth: 'Broadcast' fires and forgets — the sender continues immediately. 'Broadcast and wait' pauses the sender until all receivers finish their scripts.

Misconception: Only one sprite can respond to a broadcast message.

Truth: Any number of sprites can respond to the same broadcast. Each sprite runs its 'when I receive' script independently and in parallel.

Misconception: Broadcast Messages can send data like numbers or text.

Truth: Broadcasts only send the message name. To send data, use a variable that receivers can read after receiving the broadcast.

Knowledge Check

1. What is the main role of Broadcast Messages?

Answer: To orchestrate behaviors and controls visually

2. Which block shape starts a script stack in Scratch?

Answer: Hat block (curved top)

3. What is the maximum X coordinate limit on the stage?

Answer: 240