From Test-Scratch-Wiki

Quando alguém clicar em @greenFlag::events hat
Category Eventos
Type Chapéu
Introduced in 1.0

O bloco Quando Alguém Clicar em Bandeira Verde é um bloco de evento e um bloco chapéu. Scripts that wear this block will activate once the Green Flag has been clicked — these scripts can activate other scripts and enable the entire program.

Sem esse bloco, o único jeito um projecto poderia rodar iria ser sentindo a digitação de uma tecla ou clicando o sprite; o projeto iria somente durar até todos os scripts dependentes dos scripts de começo pararem. Este bloco também é o bloco mais usado em todo o Scratch.[1]

While it is fully possible to script projects without this block, it is not recommended; the Flag represents the start of a project, so this block will sense when the project has been started.

Exemplos de Usos

When a project is started, numerous things happen — these happenings occur at this time because they are hatted with this block. Some common uses:

Quando alguém clicar em @greenFlag::events hat
delete (all v) of [list v]
Quando alguém clicar em @greenFlag::events hat
set [variable v] to (0)
Quando alguém clicar em @greenFlag::events hat
hide
switch costume to [costume1 v]
  • Clearing all pen
Quando alguém clicar em @greenFlag::events hat
clear
  • Playing (a) song(s)
Quando alguém clicar em @greenFlag::events hat
forever
play sound [song v] until done
Quando alguém clicar em @greenFlag::events hat
create clone of [myself v]

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

Quando alguém clicar em @greenFlag::events hat
clear graphic effects
go to x: (0) y: (0)
broadcast [Start! v]
forever 
if <(meter) < (1)> then
broadcast [You Lose v]
end

Erros

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 broadcast to all other scripts that need to run when the project begins. Another solution is to click the flag multiple times or use turbo mode.

Quando alguém clicar em @greenFlag::events hat
broadcast [initialize v]

Workaround

Main article: List of Block Workarounds


when [timer v] > (-1)
say [Hello world!]

This is the only current workaround for the When Green Flag Clicked block. Scratch suppresses all hat blocks 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.

Quando receberes a mensagem [Scratch-StartClicked v] :: events
diz [Olá, mundo] :: looks

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

Quando alguém clicar a parar

"Quando alguém clicar a parar" é um bloco de evento 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:

define checar
repete para sempre :: control
reinicia o cronómetro :: sensor // reinicia o cronómetro todo décimo de um segundo para deixá-lo abaixo de 0.2
wait (0.1) secs
end

Quando alguém clicar em @greenFlag::events hat
checar

Quando o valor do sensor  o [valor do cronómetro v] exceder (0.2) :: events hat // when stop is clicked, o cronómetro não reiniciará, allowing its value to rise above 0.2
... // o que é feito quando parar é clicado
checar

Citações

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