Blocks are used to provide different actions to each sprite or backdrop. Each block contains a set of related commands called scripts. When an action is to be set for a sprite, perform the following steps:
- Click an appropriate script on the related block palette.
- Drag and attach to the previous script in the area.
Use of different blocks
In scratch programming, the different blocks used to set different actions to a sprite or backdrop are as follows:
Motion
This block is used to set movement in sprite or backdrop. Through this block, the objects will move on the stage. It includes scripts like move, turn, point, go to, etc.
Looks
Sometimes, you may need to change the appearance of a sprite or backdrop. In order to perform this task, you can choose the Looks block. When using this block, you can add different scripts like say, think, colour, show, hide, etc.
Sound
You can also add sound effects to your sprite or backdrop. To do so, select a sound script from the Sound block. Some sound scripts are play, stop, rest, set instrument, set volume, etc.
Pen
By using the Pen block, text can be stylistically written on the stage. If you want to write something related to your sprite or backdrop, select a script from the pen palette. Different options in pen block are clear, stamp, pen down, pen up, set pen colour, etc.
Events
This block includes a list of scripts for running your program. A specific script is set as tag in the beginning of the program. Various options in this block are 'when flag clicked', 'when this sprite clicked', etc. Suppose you have set an event as 'when flag clicked'. On clicking the flag, each script of your program will be executed from the beginning to end.
Control
Control block allows you to control the actions of a sprite or a backdrop. Some control options are wait, repeat, forever, if, if-else, etc. The scripts - repeat, forever and if-else are container scripts because they enclose one or more scripts within them. As soon as a container script is clicked, all the enclosed scripts are executed simultaneously.
Sensing
Sensing refers to the feature of bringing sprites into an action upon touching or clicking a mouse button. You can enable a sprite with the sensing effect. It can be done by using the Sensing block. The block contains a list of scripts like touching, colour, ask, answer, mouse down, etc. The sensing action will be activated on clicking the appropriate sensing script in the script area.
Operators
Operators are the signs or symbols that are used to perform arithmetical and logical operations on the operands.
For example: +, -, *, /, >, <, etc.
In scratch programming, some actions require mathematical operations. You may use scripts to perform such operations by using the Operators block.
More Blocks
The blocks we have discussed till now are system defined blocks. These blocks have a pre-created list of scripts. You can create a block on your own and add scripts of your choice.
To perform this task, follow the given steps:
- Click 'More Blocks' and then select the 'Make a Block' option. The 'New Block' window will appear.
- Enter the script name in the text box.
- Set parameters for the script by clicking the 'Options' tab.
- Finally, click the 'OK' button. Hence, a script is added into the block.
Use of Repeat, Forever and Forever-IF
Repeat Script
It is a container script that encloses a number of scripts to be used repeatedly. The repetition of enclosed scripts takes place for fixed number of times. Here, the user needs to provide a parameter that decides the number of repetitions.
Forever Script
It is also a container script that encloses a number of scripts to be repeated.
If-else-Script
It is a double container script that encloses scripts in two parts. The if-else script checks a given condition and if the condition is true, then it executes the scripts available in the upper container. Otherwise, the scripts of the lower container are executed.