broadcast ( v)
The Broadcast () block is an Events block and a stack block which sends a broadcast throughout the whole project. Any scripts in any sprites that are hatted with the when I receive () block that is set to a specified broadcast will activate. This broadcast block lets scripts send broadcasts without any waits in its script (unlike the Broadcast () and Wait block). Broadcasts are a good way to have sprites and scripts communicate.
In very early versions of Scratch, this block was called Wave ().
If a script must be activated without a user prompt and after the project has started, the easiest way is through broadcasts. Some common uses are:
- Communication between sprites
when this sprite clicked // in sprite1 broadcast (sprite2 move v) when I receive [sprite2 move v] // in sprite2 move (10) steps
- Connecting different events
when [space v] key pressed repeat until <touching (edge v)?> move (10) steps end broadcast (explosion v)
- Running two scripts in the same frame:
when I receive [move v] change x by (-5) change y by (10) set [script 1 v] to [done]
when I receive [move v] change x by (-5) change y by (-10) set [script 2 v] to [done]
- Preparing a scene with multiple sprites
when green flag clicked broadcast (create scene v)
|This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective.|
- Main article: Mesh
The Mesh feature allowed broadcasts to be received by other projects. It could also be used to connect different Scratch Modifications with different uses. For example, broadcasting something in the mod BYOB could be received by Enchanting, as long as they were connected via Mesh. Enchanting lacked keyboard/mouse support while BYOB could not control a robot; together they could cause a robot to react to mouse moves. See Communicating Between Scratch Modifications for more information.
- Main article: Recursion
Broadcast blocks can also, in a way, induce a form of recursion called tail recursion. Recursion happens when a block (or broadcast script in this article) calls on itself at some point in the code. It can be used to create fractals, create a forever loop, etc.