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 local variables.
The default variable name var can be changed to anything else by clicking on the name and typing in a new name in the dialog box that opens up.
Later on, if the local var's value needs to be changed, the SET VARIABLE block from the variables category can be used.
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 each time a script (including a function script) is started, and the local variables of every script invocation are independent of each other. (This 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.