Page 60 - Computer - 6
P. 60
Block Description
Changes the value of the specified variable by the specified value. (Negative value
is used to decrement the value)
Makes the variable visible and displays its value on the Stage.
Makes the variable invisible and hides its value on the Stage.
Creating a Variable
To create a variable in Scratch:
1. Under the Code tab, click the Variables blocks category. 3
2. In the Variables blocks palette, click the Make a Variable
button.
The New Variable dialog box opens. 5
3. In the New variable name box, type the name of the variable, for
example, Side.
4. Select:
• the For all sprites option to make the variable global.
• the For this sprite only option to make the variable local.
5. Click the OK button.
The variable Side is created and displayed in the Variables blocks
palette and the Stage. The blue tick mark in front of the variable
means that it will be displayed on the Stage.
Knowledge Discovery Subject Enrichment
Each Scratch 3 project begins with a default variable – my variable –
available for use.
Using a Variable
Using a variable involves either setting the value or displaying the value of the variable. Let us understand
the use of variables through a few examples.
Lab Activity 1 Experiential Learning
Let us create a variable called Counter, set its initial value to 1, and increase its value by 1 every time
the spacebar key is pressed.
1. Create a new project.
2. In the Variables blocks palette, create a variable – Counter.
3. In the Scripts area, create the stack of blocks as shown in the image.
4. Click the Go button to execute the project.
5. Press the spacebar key and observe the result.
6. Click the Stop button to end the project.
58