Page 79 - TechPluse_C4_Flipbook
P. 79
SENSING BLOCKS
The blocks in the Sensing category help the selected sprite to detect the presence of other
sprites or other elements on the stage including the edges of the stage. The blocks in the Sensing
category are colour coded as light blue.
Some of the blocks included in the Sensing category are shown along
side.
The Table below shows some important sensing blocks and their
functions.
Becomes true when the sprite touches
the mouse pointer or the edge of the
stage (defined by clicking on the drop-
down arrow)
Becomes true when the sprite touches a
defined colour
Becomes true when color1 touches color2
Becomes true when a defined key is
pressed on the keyboard
Asks a question from the user and waits
for the answer Sensing block
Stores the answer or input given by the
user
Let us develop a simple program where the cat sprite moves
towards a basketball when right arrow key is pressed. The code
for the cat sprite can be similar to this.
STORING USER INPUT
The program can also be developed to take input from the user. Earlier,
we developed a program to divide 12 by 5. Scratch gives an option to
take input from the user also.
To develop a program to divide two numbers and find the quotient,
define the script of the sprite similar to the one given alongside.
When the program is run, a small text input box opens at the bottom
of the stage. Type the value of the variable and press Enter key or
click on the tick mark symbol on the right side of the text box.
Script to divide two numbers
Game on Scratch 77

