From Test-Scratch-Wiki

当绿旗被点击
当 @greenFlag 被点击
类别 事件类积木
形狀 半圆形积木
加入於 Scratch 1.0

当绿旗被点击 (When Green Flag Clicked) 积木是一个事件类积木和一个半圆形积木。所有有这个积木的程式会在绿旗被点击时开始——而这些程式可以开启其他程式,从此而开始整个专案。[1]

如果没有这个积木,一个专案可以开始的唯一的方法是侦测用户是否按下按键或一个角色; 该专案只会持续直到所有依靠开始程式的程式已经停止。此积木是 Scratch 内最常被使用的积木。

尽管没有这个积木下仍可以编写一个专案,但不建议此方法;绿旗代表专案的开始,所以这个积木会侦测程式是否已经开始。

用法示例

当一个专案开始时,很多事儿会发生 — these happenings occur at this time because they are hatted with this block。 常见用法:

当 @greenflag 被点击
删除[list v]的所有项目
当 @greenflag 被点击
将 [variable v] 设定为 (0)
  • Setting a scene by showing/hiding 角色 and changing their 造型
当 @greenflag 被点击
隐藏
造型换成 [造型1 v]
  • Clearing all pen
当 @greenflag 被点击
全部擦除
  • Playing (a) song(s)
当 @greenflag 被点击
重复执行
 播放声音 [歌 v] 直到播放完毕
end
当 @greenflag 被点击
克隆 (自己 v)

After these occurrences, the script can continue normally. For example, (with several of those occurrences):

當 @greenflag 被點擊
效果清除
定位到 x: (0) y: (0)
廣播訊息 [Start! v]
重複無限次 
  如果 <(meter) < (1)> 那麼 
    廣播訊息 [You Lose v]
  end
end

Errors

Using more than one of these blocks in a single project can create errors that are difficult to diagnose, often only appearing with every other start of the project and can cause the timing to go off. A simple solution is to use only one of these blocks followed by a 广播 to all other scripts that need to run when the project begins. Another solution is to click the flag multiple times or use 加速模式.

當 @greenflag 被點擊
廣播訊息 [initialize v]

应用

Main article: List of Block Workarounds


當 [計時器 v] > (-1)
說出 [Hello world!]

This is the only current workaround for the When Green Flag Clicked block. Scratch suppresses all 半圆形积木 when the project first opens, and when the green flag is clicked, the timer is set to 0, and the hat block is triggered. The only problem with this method is that it automatically triggers if a user goes into a project.

當收到訊息 [Scratch-StartClicked v]
說出 [Hello, world]

Before Scratch 2.0, this workaround could be used because clicking the green flag broadcasted "scratch-startclicked".[2] However, it no longer 广播 the message, so this workaround will only work in Scratch 1.4 and below, as well as the Java 播放器.

When Stop Clicked

"When Stop Clicked" is an 事件类积木 requested by many Scratchers, that triggers when the stop sign is pressed. These requests are usually turned down, however, because the stop sign was made to stop the project, not to trigger other scripts.

A workaround for the "When Stop Clicked" block uses the following code:

定義 check
重複無限次 
  計時器重置 //  resets the timer every tenth of a second to keep it below 0.2
  等待 (0.1) 秒
end
當 @greenflag 被點擊
check :: custom

當 [計時器 v] > (0.2) //  when stop is clicked, the timer will not reset, allowing its value to rise above 0.2
. . . //  what is done when stop is clicked
check :: custom

引用

Cookies help us deliver our services. By using our services, you agree to our use of cookies.