Codecore Logo
Quick Search
Advanced Search »

Global Variables Driver

The global variables driver allows values to be persisted across script executions and can be referenced by any script.

Here is an example of using a global variable in a script:

vars.AreaCode = 312;

Local script variables on the other hand do not persist after the script execution has ended. An example of setting a local variable would be:

areaCode = 312;

See the scripting reference below for examples of using the global variable driver.

Referencing a dynamic instance property as an rvalue before it is set will cause an error. See the IsDefined() method for details.

Driver Parameters




Occurs when a variable's value changes.


  • VariableName: The name of the variable that this applies to.


Property NameTypeRead/WriteDescription
PreviousValueObjectRead OnlyGets the variable's previous value.
NewValueObjectRead OnlyGets the variable's new value.

Instance Methods


Indicates if a variable name has been defined (contains a value).

This is useful to prevent errors when checking the value of a variable that has not yet been set.


Boolean IsDefined( String variableName )


variableName : The name of the variable to check.


if ( !vars.IsDefined("Temperature") )
    vars.Temperature = 0; // default to 0

Touch Screen Keypad Example:

Here's an example demonstrating how to use a button on a virtual touch screen keypad to store which buttons were pressed. This provides a way for a user to enter a security code for example. Add the following script to each of the keypad button's OnClick actions, changing the number added to which key was pressed.

// User clicked the 1 (one) keypad button on touch screen
// so concatenate the KeyCode global variable with "1".

// Ensure variable exists before concatenating it.
if ( !vars.IsDefined("KeyCode") )
    vars.KeyCode = ""; // default to empty string

// Concatenate the KeyCode global variable with the pressed button.
vars.KeyCode = vars.KeyCode + "1";

You could then have a 'clear' button that clears the entered digits.

// User clicked the 'clear' keypad button on touch screen
// so clear the KeyCode global variable.

vars.KeyCode = "";

Instance Properties

The global variable driver doesn't have any predefined instance properties, instead it implements the concept of Dynamic Instance Properties.

Dynamic instance properties are properties on an object instance that do not exist until they are set (usually in a script) as opposed to a predefined instance property such as a string object instance's Length property.

Referencing a dynamic instance property as an rvalue before it is set will cause an error. See the IsDefined() method for details.

The global variables are set and retrieved as dynamic instance properties of a global variable driver instance. To set a global variable, reference the global variable driver by its instance name and set a dynamic instance property of the name of your choice. As with other script identifiers, the property names are case-insensitive.

Here is an example for a GlobalVariableDriver that was defined in the configuration with an InstanceName of vars:

vars.Amount = 1;
vars.LastName = "Smith";
media.TextToSpeech( vars.LastName );

Privacy Policy | Conditions Of Use

Copyright ©2014 Codecore Technologies, All rights reserved.