Scratch for Kids

A Watch the course on Frontend Masters

Broadcasting A Message

Let’s say we want to have a Game Over screen. Ideally, this would show when the game ends, right? But, how does the screen know?

Well, sprites can broadcast messages. But, first let’s start by hiding our game over screen when the game begins.

when green flag clicked
hide

And then in our player, we’ll add the following to the game loop.

if <touching (Enemy v)> then
	broadcast (Game Over v)
end

Back in our Game Over sprite, we’ll listen for that message.

when I receive [Game Over v]
show
stop [all v]

And that will do it! Broadcasting is super useful when you need to communicate between sprites.