From Test-Scratch-Wiki

Translate: - English - 中文 
广播讯息 () 并等待
2.0 Broadcast () and Wait.png
Category 事件类积木
Type 条形积木

The Broadcast () and Wait 积木 is a 事件类积木 and a 条形积木. The block sends a 广播 throughout the whole Scratch 专案 — any 程式 that are halted with the 当收到讯息 () block and are set to the broadcast will activate. This broadcast block lets scripts send 广播, and have them wait until all scripts activated by the broadcast end (unlike the [[Zho:广播讯息 ()(积木)|广播讯息 ()] block, which will let its script continue without it waiting for the scripts activated by the broadcast). 广播 are a good way to have 角色 and scripts communicate.

How to Write it in the Forums or Wiki

broadcast [message1 v] and wait

用法示例

If a script must be activated without a user prompt and after the 专案 has started, there is only one way — 广播. Some common uses:

當收到訊息 [Sprite1 Talk v]
說出 [Hi, Gobo!] (2) 秒
廣播訊息 [Sprite2 Talk v] 並等待
說出 [Let's talk about food.] (2) 秒
  • Ordinary animations
滑行 (1) 秒到 x: (-148) y: (80)
播放音效 [meow v]
廣播訊息 [move v] 並等待
  • Waiting for an online data decoding before starting
當 @greenflag 被點擊
廣播訊息 [decodeCloudData v] 並等待
詢問 [enter your password to resume your progress!] 並等待
變數 [i v] 設為 [1]
重複直到 <(清單第 (i v) 項項目 [user v] :: list) = (用戶名稱)> 
  變數 [i v] 改變 (1)
end
decrypt password :: custom
如果 <(詢問的答案) = (properPassword)> 那麼 
  廣播訊息 [playGame v]

  廣播訊息 [cannotPlay v]
end
變數 [chat v] 設為 [1]
廣播訊息 [P2 chat v] 並等待

Recursion

Main article: Recursion


Broadcast blocks can also, in a way, induce 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.

参见