![]()
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
$Xand$xto be different variables.Some examples of valid variable names:
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$wtbare 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:
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:
- The MEL interpreter comes across code that tries to access a variable you haven’t declared.
- You try to declare the same variable twice with different types.