This block is actually a button. It creates a new global variable.
If a variable with the same name exists, the new one will be created with the same name with the number 2 appended.
e.g.: variable with name test exists. Another one is created with the same name. The new one's name becomes test2.
The two pictures below depict the creation of test variable, followed by its appearance in the variables list.
This block is actually a button. It is normally not visible, unless at least one variable has been created. Once a variable is created, this button is used to delete it.
The two pictures below depict the variable deletion process.
When DELETE A VARIABLE button is clicked, a list of all global variables is presented. Here variable total is to be deleted. It is selected and clicked.
The second picture is the status of the variables display with the remaining variables.
This block is used to assign values to variables. Its selection menu will display a list of all global and local variables.
To display the names of the local variables in the selection menu, this block has to be physically attached to the sequence of blocks where the INITALIZE LOCAL block is used.
In addition to displaying the names of the variables, the selection menu also displays an option for adding a variable. This can be used to add variables while editing the program code, without switching to the variables category options.
The example code shows the creation of a local variable var and assignment of value 123 to the global variable test.
This block changes value of any variable, global or local, by the amount specified in the input area. The change amount can be a positive or a negative number.
The program changes values of the two variables test and var.
This block is used to create and initialize a local variable. A local variable can only be used in the script in which it appears and it is re-initialized every time the script is run; its value is NOT retained. Local variables with the same name in different scripts are entirely independent of one another.
The default variable name var can be changed by clicking on the name and typing in a new name in the dialog box that opens up.
The set variable or change variable blocks can be used to change the value of the local variable anywhere in the script.
A global variable has:
Global scope: A global variable can be used in any script that doesn't have local variable of the same name that overrides it.
Long lifetime: A global variable is created explicitly and lives until it is explicitly deleted. It retains it's value as scripts start and stop and even when no scripts are running. However, clicking the "stop" button clears all global variables to the value zero. Global variables are also initialized to zero when they are first created and when a project is loaded.
In contrast, a local variable has:
Local Scope: A local variable can be used only in the script where it appears. If several scripts use local variables with the same name, those variables are independent of each other.
Limited lifetime: A local variable for a script is created when the script is started and deleted when the script terminates. A new local variable is created and re-initialized each time the script is run; the value of the variable is not retained. If a function calls itself recursively, the arguments and local variables in each function call are independent of each other. (That is what makes recursion possible.)
Precedence over globals: If a local variable has the same name as a global variable, the local variable overrides the global in the script in which the local variable appears. A variable is local in the entire script no matter where in the script the "initialize local var to" appears (although it is good coding practice for the "initialize local var to" to precede any other references to that variable).
Everything about local variables also applies to the parameter variables of a function. You can think of parameters as local variables that were pre-initialized by the calling script.
See examples above.