Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 99 - 2611_SmartGPT Pro V(5.0) C-5
P. 99

    We have already learnt how to change the costume of a sprite and to work with two
                     sprites in previous class. Now, in this chapter, we will learn to create variables and control
                     the sprites' movement more effectively in a game.

                               VARIABLES IN SCRATCH

                     Variables are used to hold information such as words or numbers. Variables are named
                     locations where you can store information. We can create variables for one or for all the
                     sprites.

                     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

                     Local variables can only be accessed or modified from the sprite where it was created.

                     CREATING A VARIABLE

                      To create a variable, follow the given steps:

                                                                                          4  Select whether the
                                                                2  Click on Make          block is ‘For all sprites’ or
                                                                a variable.               ‘For this sprite only’.

                                                                 3  Type a name
                                                                 in New Variable
                                                                 name box.

                             1  Click on the Variables Block.                                5  Click on OK button.

                          Tick ( ) if you know this.
                          ▶   Variables are a named location where you can store information.

                          ▶   We can create our own variables in Scratch.

                                                                                                      More on Scratch  97

| 94 95 96 97 98 99 100 101 102 103 104 |