Page 46 - Code & Click - 6
P. 46

3.  In the New variable name box, type the name of the variable, for
                  example, Side.
              4.  Select:
                  •  the For all sprites option to make the variable available       3
                     to all sprites.

                  •  the  For  this  sprite  only  option  to  make  the  variable
                     available to only an sprite.

              5.  Click the OK button.                                                                        5
                  The variable Side is created and displayed in the Variables blocks palette and the Stage. The
                  blue tick mark in front of the variable means that it will be displayed on the Stage.


















            Using a Variable
            Using a variable involves either setting the value or displaying the value of the variable. Let us
            understand the use of variables through a few examples.

                                                                                                 Experiential Learning
              Lab Activity 1
             Let us create a variable called Counter, set its initial value to 1, and increase its value by 1 every
             time the spacebar key is pressed.
              1.  Create a new project.

              2.  In the Variables blocks palette, create a variable – Counter.
              3.  In the Scripts area, create the stack of blocks as shown in the image.
              4.  Click the Go     button to execute the project.
              5.  Press the spacebar key and observe the result.

              6.  Click the Stop   button to end the project.
                  The sample images for the project are given below.



















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