Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 115 - CodePilot V5.0 C5
P. 115

    There are two types of variables in Scratch:

                         Global Variables: These variables are created on any sprite and can be accessed
                         or modified by other sprites in the project by choosing For all sprites.

                         Local Variables: These variables are created for a specific sprite and can only
                         be used by that sprite, selected by choosing For this sprite only.

                     The variable blocks used in Scratch are:

                                                       This block refers to a custom variable that you create
                                         my variable
                                                       in your project.

                           set  my variable  to  0     This block sets the selected variable to a specific value.

                                                       This block adds or subtracts a certain number to the
                        change my variable  by  1
                                                       variable.

                                                       This block shows the value of the chosen variable on
                           show variable  my variable
                                                       the screen.

                           hide variable  my variable  This block hides the chosen variable from the screen.

                            CREATING A GAME IN SCRATCH

                     Have you ever dreamt of creating a computer game?

                     Here’s  your chance to turn it into reality with a Scratch project. Let’s learn how to
                     create a game in Scratch using Sensing blocks and Variables to make the game

                     more interactive and engaging.

                     To create a game in Scratch, follow the given steps:

                     Step    1    Choose a sprite as the main character of your game (a cat or a player).

                     Step    2    Add another sprite to be a target the player needs to touch (a star).

                     Step    3    Create a Variable and name it score v for the player sprite.

                     Step    4    Place the Star sprite at a random position on the stage.

                     Step    5    Choose a suitable backdrop for the game.

                     Step    6    Now, create the given script for your player sprite.

                                                                                                    Scratch Meets AI   113

| 110 111 112 113 114 115 116 117 118 119 120 |