Accessing global variables

 
 
 

To reference a global variable, you must explicitly declare it in the scope in which it is used

This is necessary because MEL allows the implicit declaration of variables through assignment. For example,

$flag = 42;

implicitly declares $flag to be an integer defined within the current scope.

MEL can’t discern whether the you mean to reference a global variable $flag or to define your own locally. Requiring you to explicitly declare globals before referencing them relieves you from having to be aware of all the global data that can exist within Maya’s system.