Zho:广播讯息 ()（积木）

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.

用法示例
If a script must be activated without a Scratch 用户 prompt and after the 专案 has started, the easiest way is through 广播. Some common uses:
 * 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.

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.

参见

 * 广播讯息 并等待
 * 当收到讯息
 * 广播

Sende an alle (Block)