Scope


In MEL there are two kinds of scope for variables: global and local.
Global variables exist from when they are created until Maya is closed.
Execute the first script in the script editor, then the second script.

First Script:

int $twelve = 12;
int $one = 1;
int $answer = $twelve + $one;
print $answer;


Second script:

string $twelve = "twelve";
string $one = "one";
string $answer = $twelve + $one;
print $answer;


You should get a bunch of errors looking something like this.

// Error: string $twelve = "twelve";
//
// Error: Line 1.16: Invalid redeclaration of variable "$twelve" as a different type. //
// Error: string $one = "one";
//
// Error: Line 2.13: Invalid redeclaration of variable "$one" as a different type. //
// Error: string $answer = $twelve + $one;
//
// Error: Line 3.16: Invalid redeclaration of variable "$answer" as a different type. //

The problem is that those original int variables are still floating around in global name space.
This is easy to fix. Modify the script by adding brackets at the beginning and end like this.

{
string $twelve = "twelve";
string $one = "one";
string $answer = $twelve + $one;
print $answer;
}

Putting the script inside those brackets causes the variables to be created in a local space.
When the script reaches the end of the brackets the variables are removed.
Its a good idea to always enclose any script you write inside brackets so you won't accidentally create global variables.