From Test-Scratch-Wiki
Broadcast () and Wait | |
Category | Event |
Type | Stack |
The Broadcast () and Wait block is a Event block and a Stack block. The block sends a broadcast throughout the whole Scratch project — any scripts that are halted with the When I Receive () block and are set to the broadcast will activate. This broadcast block lets scripts send broadcasts, and have them wait until all scripts activated by the broadcast end (unlike the Broadcast () block, which will let its script continue without it waiting for the scripts activated by the broadcast). Broadcasts are a good way to have sprites and scripts communicate.
How to Write it in the Forums or Wiki
broadcast [message1 v] and wait
Example Uses
If a script must be activated without a user prompt and after the project has started, there is only one way — broadcasts. Some common uses:
- Talk show animations
When I receive [Sprite1 Talk v] say [Hi, Gobo!] for (2) secs broadcast [Sprite2 Talk v] and wait say [Let's talk about food.] for (2) secs
- Ordinary animations
glide (1) secs to x: (-148) y: (80) play sound [meow v] broadcast [move v] and wait
- Waiting for an online data decoding before starting
when gf clicked broadcast [decodeCloudData v] and wait ask [enter your password to resume your progress!] and wait set [i v] to [1] repeat until <(item (i) of [users v]) = (username)> change [i v] by (1) end decrypt password ::custom if <(answer) = (properPassword)> then broadcast [playGame v] else broadcast [cannotPlay v] end
- Mesh projects
set [chat v] to [1] broadcast [P2 chat v] and wait
Recursion
- Main article: Recursion
Broadcast blocks can also, in a way, induce 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.