Broadcast () and Wait
broadcast ( v) and wait
Category Events
Type Stack

The Broadcast () and Wait block is an Events block and a stack block. The block sends a broadcast throughout the whole Scratch project. Any scripts that start with the When I Receive () block and are set to the matching broadcast will activate. This broadcast waits until all scripts activated by the broadcast end and stop running. Broadcasts are a good way to have sprites and scripts communicate.

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:

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
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
set [chat v] to [1]
broadcast (P2 chat v) and wait

Recursion

Main article: Recursion

Recursion is a process where a script calls into itself. Broadcast scripts can perform a limited kind of recursion, called tail recursion, by broadcasting their own message at the end of the script, restarting the script and forming a loop.

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.