⭐ Guided activity: Creating a variable
After defining this, we can start to create a new variable.
1. Select the Stage and go to the Variables blocks. Click on the Make a Variable button to display the New Variable dialog box.
Figure 150: Creating a variable
2. Type in the name of your variable, “Timer” in this example.
3. Choose if the variable will be for all sprites or for the sprite you are creating only. That introduces the difference between global and local variables. So, you have come to the crossroads: do you choose for all sprites or do you choose for your sprite only?
The choice you make (for all sprites or for this sprite only) will affect the use of the variable in the whole project.
If you select for all sprites, your variables become global, meaning that it can be changed or accessed from any sprite in your project, regardless on which sprite it was created. On the other hand, if you choose for this sprite only, your variable will become local. A local variable is one that can only be changed or accessed from the sprite on which it was created.
For example, the internet is global, and anything saved online can be accessed using any computer in the world! However, if you save something to the hard drive of your computer, you will not be able to access it on a different device as it was saved locally.
4. Click the OK button.
5. Your variable will now be displayed on the stage, and variable blocks will appear that you can use to manipulate it.
Figure 151: Displaying a variable on the stage