Page 113 - 2502_Pakistan-kifayat_C-7
P. 113
Setting a Variable
You can set the value of the variable by use the block set [variable v] to (value). For this you need to give
the variable an initial or specific value. It is usually used at the beginning of a program to initialise the
variable.
For example, set the value of the score variable to 5.
Changing a Variable
You can change the value of the variable by using block change [variable v] by (value) to increase or
decrease the variable’s value. It is commonly used in games, like increasing the score when the player
earns points.
For example, increase the value of the score variable by 3.
GAME: CATCH THE APPLE BEFORE TIME RUNS OUT!
Objective:
The Cat (player) moves to catch the Apple.
Each time it touches the Apple:
• Score increases by 1
• Apple moves to a random location
A countdown Timer starts from 20 and decreases by 1 every second.
The game ends when the Timer reaches 0.
Steps for creating a game are as follows:
Step 1: Add two sprites, namely, Cat and Apple
Step 2: Add any background to the backdrop
#More on Scratch 111

