Page 45 - Code & Click - 6
P. 45

6                                        Advanced Scratch 3







                  Pre-Processing
                  Pre-Processing
                        • Working with Variables                         •  Working with Operators
                        • Combining the Elements


            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 used or changed during the execution of a script.
            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 Blocks
            Variables in Scratch are represented and manipulated by using blocks in the Variable blocks category.
            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.
                                 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.
              2.  In the Variables blocks palette, click the Make a Variable              button.


                                                                                                                 43
   40   41   42   43   44   45   46   47   48   49   50