broadcast () and wait

From PenguinMod Wiki (Official)
Revision as of 20:50, 29 July 2024 by MediansSC (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Broadcast () and wait
Jump to navigation Jump to search

The broadcast () and wait block is a stack block in the Events category that broadcasts a message, but then waits for all sprites to finish running the code associated with the message. It originates from Scratch. The default selected broadcast is the same as the broadcast () block (i.e. the last created broadcast).

It can be used to only do animations or speech after another sprite has finished:

say [Hello there, children!]
speak [Hello there, children!]
broadcast (children speak v) and wait
say [How's it going?]
speak [How's it going?]

Workaround

This block can be worked around by using a variable or a list to signify when the message is done in a sprite, and using the broadcast () block:

broadcast (name v)
set [broadcast complete? v] to [false]
wait until <(broadcast complete?)::operators>
code::grey
when I receive [name v]
code::grey
set [broadcast complete? v] to [true]