Page 72 - TP_Modular_V2.1_Class5
P. 72

VARIABLES

                  A program is a set of instructions that tell the computer to carry out a task. In
                  scratch, a program is called a Script. A Script is made up of a number of blocks. So,

                  the blocks are the commands or instructions that we give to the sprite to perform
                  a task.
                  All the numbers, text, date or pictures that we use in a program are called data. We
                  store this data in the computer memory so that we can get information from it later.

                  This data is stored in variables. It is called variable because it does not have a fixed
                  value, its value changes. You can modify this value of a variable according to your script.
                  Types of Variables


                  There are two types of variables. They are as follows:
                  Global Variables

                  If a variable is created to be used and modified by all the Sprites, then it is known
                  as a global variable. A Global variable can be created on any Sprite but its value
                  can be accessed or modified by other Sprites used in the project.

                  Local Variables
                  If a variable is created to be used and modified by a single Sprite only, then it is
                  known as a local variable. Local variables can only be accessed or modified from
                  the Sprite where it was created.

                  Creating Variables in Scratch

                  To create variables in Scratch, follow the given steps:
                  Step 1   Click  on  Variables  block  category.
                            A  set  of  blocks  appears in  the  block                                          2
                            palette.

                  Step 2   Click on Make a Variable block. A New
                            Variable dialog box appears. Type a
                            variable name in  the  New  variable
                            name box.

                  Step 3   Click on the radio button of either of
                            the options. Click on For all sprites if
                            you want this variable to appear for all             1
                            the sprites.

                            Or

                              Click on For this sprite only if you want this variable to appear for this
                            sprite only. Here we have added the variable fruit. It will be available
                            for all the sprites.



                   70       Modular (Ver. 2.1)-V
   67   68   69   70   71   72   73   74   75   76   77