Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » Broadcast vs Broadcast and wait
- kentkoide
-
100+ posts
Broadcast vs Broadcast and wait
In Scratch, there are these 2 blocks.
but I just don't know the difference I used both blocks in a simple project, and the broadcast “and wait” block didn't actually last longer than the “broadcast” block. Can somebody tell the difference please?
broadcast [ v]
broadcast [ v] and wait
but I just don't know the difference I used both blocks in a simple project, and the broadcast “and wait” block didn't actually last longer than the “broadcast” block. Can somebody tell the difference please?
Last edited by kentkoide (May 8, 2022 07:53:07)
- Adzboy
-
1000+ posts
Broadcast vs Broadcast and wait
Broadcast:
Broadcast and wait:
Links to Scratch Wiki articles:
Broadcast
Broadcast and wait
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).
Broadcast and wait:
This broadcast waits until all scripts activated by the broadcast end and stop running.
Links to Scratch Wiki articles:
Broadcast
Broadcast and wait
Last edited by Adzboy (May 8, 2022 08:11:22)
- historical_supa
-
1000+ posts
Broadcast vs Broadcast and wait
The first one just broadcasts the message and then moves on to the new block. No pauses or anything.
The second one waits until all the scripts that are activated by the broadcast end, so to put it simple: They're like custom blocks, except they're global.
Ninja'd
The second one waits until all the scripts that are activated by the broadcast end, so to put it simple: They're like custom blocks, except they're global.
Ninja'd
Last edited by historical_supa (May 8, 2022 08:12:27)
- E_Equals_EmCeCube3
-
1000+ posts
Broadcast vs Broadcast and wait
“Broadcast and wait” pauses the code until all scripts that are initiated by
For example:
If you instead used “broadcast” (without the wait), the first script would have prematurely continued on to the if statement and the code would not run properly.
when I receive [ v]have fully completed running, whereas “broadcast” continues without pausing.
For example:
broadcast [ask v] and waitHere, the “broadcast and wait” block pauses the first script until the second script has fully run.
if <(answer) = [10]> then
say [Correct!]
when I receive [ask v]
ask [What is 6 + 4?] and wait
If you instead used “broadcast” (without the wait), the first script would have prematurely continued on to the if statement and the code would not run properly.
Last edited by E_Equals_EmCeCube3 (May 8, 2022 08:13:50)
- colinmacc
-
1000+ posts
Broadcast vs Broadcast and wait
Also worth noting that “broadcast and wait” happens immediately, but “broadcast” adds to the stack and happens when the current thread finishes or you get to a yield point.
- kentkoide
-
100+ posts
Broadcast vs Broadcast and wait
Broadcast:I don't really get it.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).
Broadcast and wait:This broadcast waits until all scripts activated by the broadcast end and stop running.
Links to Scratch Wiki articles:
Broadcast
Broadcast and wait
- E_Equals_EmCeCube3
-
1000+ posts
Broadcast vs Broadcast and wait
Here's an example based on what I wrote above. I don't really get it.
Put this script in one sprite:
when green flag clickedAnd put this script in the Stage's code:
broadcast [ask v] and wait
say (join [Hello, ] (answer))
when I receive [ask v]
ask [What is your name?] and wait
Click the green flag and see what happens. It works normally, right? You are prompted with the question “What is your name?” and the sprite says hello to you. Now replace "broadcast [ask v] and wait“ with ”broadcast [ask v]“. What happens?
The answer is that the first script had already run the ”say hello“ block before you got a chance to answer the question. The ”wait“ fixes the problem by pausing the first script until the second script (and any other script initiated by ”when I receive [ask v]") has finished running completely — in other words, it pauses the first script until you have answered the question.
- Discussion Forums
- » Questions about Scratch
-
» Broadcast vs Broadcast and wait