Variables

You use variables as symbolic names for values. Variables can hold different values at different points in a script.

Variable names always start with a dollar sign ($). The name can contain letters, numbers, and underscores (_). The first character of the name (after the $) cannot be a number.

Variable names are case sensitive. MEL considers $X and $x to be different variables.

Some examples of valid variable names:

$x
$floaty5000
$longDescriptiveName
$name_with_underscores
$_line

To keep your MEL script clear and understandable, use a variable name that describes the variable’s function.

Variable names such as $x, $t, and $wtb are not as informative as $carIndex, $timeLeft, and $wingTipBend. However, do not be too verbose. For example, $indexForMyNameArray, is overly descriptive.

Declare variables before using them

Before you can use a variable you need to declare it. Declaring the variable tells Maya you intend to use a variable with this name, and specifies the type of values the variables can hold.

To declare a variable, use a explicit type keyword followed by the variable name. For example:

float $param;
int $counter;
string $name;
vector $position;

Having to declare variables before you use them prevents a set of common problems where misspelled or misplaced variables create hard-to-find bugs. The MEL interpreter will complain if you try to do the following: