Page 134 - TGPT_V5.0_C5_Flipbook
P. 134

Type a variable name                                  Click  on  the

                    3   in the New variable                                   radio button
                        name box.                                             of  either  of
                                                                              the options.    4







                                                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.

              Let's create a small script using variables to add two numbers by getting input from the user

              using the ask block. To do this, create variables named Number 1, Number 2, and Sum. Now,
              create the following script:






                                                                      Factbot

                                                               Every time you type a name or number,
                                                               the previous value in the variable gets
                                                               deleted and the new value is stored.


              When you press the Green flag the sprite will prompt you to enter the first number. After
              pressing the Enter key, the number will appear in the sprite's speech bubble. Next, the

              sprite will ask for the second number, which will also be displayed in the speech bubble
              upon pressing Enter. Finally, the sum of both numbers will be shown in the sum variable
              and the speech bubble.

























                  132  Premium Edition-V
   129   130   131   132   133   134   135   136   137   138   139