Page 86 - ThinkGPT_V2.1_C5_Flipbook
P. 86

All the numbers, text, dates, 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 a variable because it does not have a fixed value, its value
                  changes. For example, in the move block, the variable has a value 10 by default. You can
                  modify this value 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:


                                            2  Click on  Make  a Variable  block.  Type  a
                                            variable name in the New variable name box.






















                       1  Click on Variables
                       block category.





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

                  The variable appears in the list of Variables blocks. Observe that the variable name fruit
                  appears in all the blocks. Now create the following script.


                       84    Premium Edition-V
   81   82   83   84   85   86   87   88   89   90   91