Getting Started Guide
CLASS 4
50
Do you remember the ‘If~’ block used in the previous page?
It was a block that activates the script when certain condition is satisfied. Then the ‘If~’ block for number 1 to 6
will be made.
Which means that there will be six ‘If~’ block connected. Then what should happen to the script inside the each
‘If~’ block?
They must be similar to each other. This is because as long as the ‘Action = number input’ condition is confirmed,
the behavior that must be expressed is same.
Therefore, if you make a script inside “If ’Action=1’” block accurately, then the following tasks are relatively easy.
Then let’s learn what kind of script goes into the “If ‘Action=1’”.
Mole game coding activity
Mole game ‘If~’ block repetition
Look at the script above. In the ‘Action’ variable, there is some variable between 1-6 stored, and this is a script
that runs when the number stored is 1. Shall we take a look at what blocks are inside?
First, we need a sound to tell users to press ‘1.’ Computer must sound ‘1’ and initialize the timer. Timer, in this
case, is a stopwatch processing inside the scratch program. If you initialize the timer, the time becomes 0 second.
Then use the ‘waiting’ block to wait until the Analog 0 port IR sensor is pressed or until the timer exceeds the time
saved in the ‘Timeout’ variable. So, if the user presses the analog 0 sensor before the time saved in the ‘Timeout’
variable they will escape the “waiting” block. Or, if they fail to press the correct sensor before the time saved in the
‘Timeout’ variable, they also escape the “waiting” block. The reason why we connect these two conditions with
“Or” block is because you will escape the waiting block if only one of the condition is satisfied. If we had to satisfy
both of the conditions, we would have used the ‘and’ block.