Page 71 - CloudGPT_C5_Flipbook
P. 71

VARIABLES

                 A program is a group of commands and 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. For
                 example, in the move block, the variable has a value 10 by default. You can modify this value
                 according to your script. Variables can store numbers as well as letters.

                 Creating Variables in Scratch

                 To create variables in Scratch, follow the given steps:

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



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


                                                                                                      Click on
                                                                                                      the radio
                                                                                                      button of
                                                                                                      either of the   4
                                                                                                      options.



                  1   Click on Variables
                      block category.

                                                                         5
                                                                             Click on Ok button.




                 The variable appears in the
                 list of  Variables blocks.
                 Observe  that  the  variable
                 name fruit  appears in  all

                 the blocks.

                   Now  create  the  following                                      Factbot
                 script:
                                                                             Every time you type a name or number,
                                                                             the previous value in the variable gets
                                                                             deleted and the new value is stored.





                                                                                                 More on Scratch   69
   66   67   68   69   70   71   72   73   74   75   76