Introduction to Variables
-
Description
A variable is like a box. It allows your program to “remember things”.
For example, you can store a number in a box:
Later, you can check what’s in the box:
You can also read out the number, change it, then put the new number back:
Making a Variable
To make a new variable, go to the “Variables” group, and click “Make a Variable”. You need to give it a name, such as “number”, then click “OK”. Note that every variable needs to be named differently.
Renaming a Variable
If you want to change the name of a variable, you can right-click on it, then select “Rename variable”.
Deleting a Variable
To delete a variable, you can right-click on it, then select “Delete the [censored] variable”.
Show or Hide a Variable
If you check the box to the left of a variable, it will be displayed on the stage, so that you can easily check its value. If you uncheck that box, the variable will disappear.
Setting a Variable’s Value
To set the value of a variable, you can use this block:
You need to select which variable to set, and then input the value. The value can be a number or some text.
Note that when you save the project, the value of a variable is saved as well. So the next time you open this project, the variable will contain the same value.
Reading a Variable’s Value
To read the value of a variable, you can use the reporter block:
Changing a Variable’s Value
If a variable contains a number, you can use the “change variable” block to increase or decrease its value.
If you do not know how to use negative numbers, you can use the “reduce variable” block instead:
Show or Hide a Variable Using Blocks
Lastly, you can use these 2 blocks to hide or show a variable. For example, in your program, you might want to show a variable briefly then hide it.
-