Page 59 - Computer - 6
P. 59
6 6 Advanced Scratch 3
Advanced Scratch 3
Pre-Processing
• Working with Variables • Working with Operators
• Combining the Elements
Scratch is one of the easiest languages to understand the basics of programming. It provides a fun,
visual environment to create programs. You have learned to use various blocks and sprites to create
animation. Let us now learn about some advanced programming concepts such as variables and
conditional statements. We will also learn to combine all the elements to create an animated story.
WORKING WITH VARIABLES
A Variable is a temporary location in the computer’s memory that has a name and stores data. The value
stored in the variable can be changed during the execution of a script. Variables can be used to change
the position of the sprite, run a script a specified number of times, check for a specified condition to be
True or False, or perform mathematical calculations.
Types of Variables
Scratch 3 allows variables of three types:
• Numeric variables – Numeric variables are used to store numbers. Mathematical calculations,
such as addition and multiplication, can be performed on numeric variables.
• String variables – String variables are used to store text values. Strings can include digits, letters,
and symbols. Mathematical calculations cannot be performed on string variables.
• Boolean variables – Boolean variables are used to store logical values – True or False. Boolean
variables are used for taking decisions based on conditions in a script.
Variables in Scratch 3 can be local, global, or cloud variable.
• Local variable : A local variable can be used by only one sprite in a project.
• Global variable : A global variable can be used by all the sprites in a project.
• Cloud variable : A cloud variable allows users to store variables on the Scratch server.
Variables Blocks
Variables in Scratch are represented and manipulated by using blocks in the Variable blocks category.
These blocks are used to perform actions, such as assigning values to a variable, changing values during
execution of a script, and hiding or displaying a variable. Variables blocks are colour-coded orange.
The common variable blocks in Scratch 3 are described in the table below.
Block Description
Reports the value of a variable.
Sets the specified value to the specified variable.
57