The special Global Variables which are Global1 through to Global10, are automatically declared within the script engine. You do not need to declare these yourself to use them.

They are declared as follows.

var Global1 : Variant;
var Global2 : Variant;
. . .
var Global10 : Variant;

Each Map contains its own set of Global Variables. The Global Variables are global to each execution of a Map, but they are not shared between Maps, or even between different executions of the same Map.

Therefore, if you have 2 Maps, and within one you set Global1 to have the value of 20, you will not be able to access this value through Global1 in the second Map.

But since the Global Variable is global to the Map, you can set its value in one event and reference it from another. So, if within field 1 OnMap you set Global1 to the value of 20, you can read this value from the field 2 OnMap.

Global Variables are naturally persistent, which means that it will retain its value for the entire execution of the Map. However the next execution of the Map will have its own set of Global Variables, which will be initialised and set to null when the Map is executed for that subsequent time.

An example of using Global variables is below. In this example the Global1 variable is being used as a flag. In the example, throughout the Map checks are made and Global1 is set to true accordingly.

procedure ScriptEvent (var Value : variant);
begin
if Value > 10 then
Global1 := True;
end;

As an extension of the above example, another example shows a later event (potentially OnEndMap) where the value of Global1 is checked, and depending on the flag, then sends an error message..

procedure ScriptEvent (var Value : variant);
begin
if Global1 = True then
LogError('Something happened during execution so this error is raised');
end;