From Test-Scratch-Wiki
(Redirected from Eng:Broadcast ())
Broadcast () | |
Category | Event |
Type | Stack |
The Broadcast () block is a Event block and a stack block which sends a broadcast throughout the whole Scratch program. 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 Scratch 0.1, this block is called Wave ().
How to Write it in the Forums or Wiki
broadcast [message1 v]
Example Uses
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:
- 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
broadcast [All sprites get ready! v]
- It can also be used to connect two different projects with Mesh.
- It can be used to connect different Scratch Modifications with different uses. For example, broadcasting something in the mod BYOB can trigger an event in the mod Enchanting, which makes your Lego Mindstorms robot do something. Enchanting lacks keyboard/mouse support while BYOB can not control a robot; together they can get a robot to react to mouse moves. See Communicating Between Scratch Modifications for more information.
Recursion
- 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.