The Broadcast () 积木 is a 事件类积木 and a 条形积木 which sends a 广播 throughout the whole Scratch program. Any 程式 in any 角色 that are hatted with the 当收到讯息 () block that is set to a specified broadcast will activate. This broadcast block lets scripts send 广播 without any waits in its script (unlike the 广播讯息 () 并等待 block). 广播 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]
- Communication between sprites
當角色被點擊 // in sprite1 廣播訊息 [sprite2 move v] 當收到訊息 [sprite2 move v] // in sprite2 移動 (10) 點
- Connecting different events
當 [空白 v] 鍵被按下 重複直到 <碰到 [邊緣 v] ?> 移動 (10) 點 end 廣播訊息 [Explosion! v]
- Running two 程式 in the same frame:
當收到訊息 [Move v] x 改變 (-5) y 改變 (10) 變數 [Script 1 v] 設為 [done]
當收到訊息 [Move v] x 改變 (-5) y 改變 (-10) 變數 [Script 2 v] 設為 [done]
- Preparing a scene with multiple sprites
廣播訊息 [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 修改版s 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.
- 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.