MAXScript Language Reference > Variables - Assignment and Scope > Global and Persistent Global Variable Methods >

# globalVars Structure

The globalVars struct provides methods to collect, create, test and remove global variables.

These methods are available in 3ds Max 2008 and higher.

They were previously available in the Avguard Extensions.

Methods:

    globalVars.get <global var name>

Returns the value of the specified global variable.

The argument must be a MAXScript name value.

The global variable name must exist, otherwise a runtime error will be generated.

    globalVars.set <global var name> <value>

Sets the value of the specified global variable.

The argument must be a MAXScript name value.

The global variable name must exist, otherwise a runtime error will be generated.

FOR EXAMPLE:
    globalVars.get #dontknow --try to get an undeclared variable
    -- Runtime error: Specified global variable does not exist: #dontknow
    global dontknow = "Now I Know" --declare the variable
    --> "Now I Know"
    globalVars.get #dontknow --now we can get and set the value
    --> "Now I Know"
    globalVars.set #dontknow "I Still Know What You Did Last Siggraph"
    --> "I Still Know What You Did Last Siggraph"
    globalVars.set #reallydontknow "MAXScript"
    -- Runtime error: Specified global variable does not exist: #reallydontknow

    globalVars.gather()

Returns an array of all global variable names declared in the current session.

    globalVars.isglobal <var name>

Returns true if the specified variable name is global, false if it is not global or not declared.

EXAMPLE (CONTINUED FROM PREVIOUS EXAMPLE)
    globalVars.isglobal #dontknow --declared in previous example
    --> true
    globalVars.isglobal #reallydontknow --still notdeclared
    --> false

    globalVars.getTypeTag <var name>

Returns the type of the global variable as an integer or name value.

The specified global variable name must exist.

This method is mainly for internal testing.

The primary type tag values are:

10 - general global

11 - constant global

12 - system global

EXAMPLE (CONTINUED FROM PREVIOUS EXAMPLE)
    globalVars.getTypeTag #dontknow --declared in previous example
    --> 10P
    globalVars. getTypeTag #reallydontknow --variable does not exist
    -- Runtime error: Specified global variable does not exist: #reallydontknow

    globalVars.getValueTag <var name>

Returns the type of the value in the global variable as an integer or name value.

The specified global variable name must exist.

This method is mainly for internal testing.

Each value type has its own tag value.

FOR EXAMPLE:
    global aString = "I Know Kung-Fu!"
    --> "I Know Kung-Fu!"
    global aFloat = 123.456
    --> 123.456
    global anInt = 42
    --> 42
    global aMatrix = matrix3 1
    --> (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
    globalVars.getValueTag #aString
    --> #String
    globalVars.getValueTag #aFloat
    --> #float
    globalVars.getValueTag #anInt
    --> #integer
    globalVars.getValueTag #aMatrix
    --> #Matrix3
    globalVars.getValueTag #reallydontknow
    -- Runtime error: Specified global variable does not exist: #reallydontknow

    globalVars.remove <var name>

Removes the specified variable name from the list of global variables.

WARNING!
Use With Caution!

#### See Also

- Persistents Structure

- Variables - Assignment and Scope

- Variable Assignment

- Scope of Variables

- Specifying Global Variables As Global Using ::