2010

Table Of Contents
Name and type cannot change after creation. The value of a variable can
change, but the value must be of the earlier defined type.
NOTE Variables in MEL should always have their type explicitly defined. If not
explicitly stated, the scripting language attempts to imply a data type for the
variable from the context of the first appearance of the variable. It is good practice
to explicitly declare variables as implicitly defining variables can lead to scripting
errors and slows down the execution of the script.
To store scene information as a variable
1 In the Script Editor, type the following and press enter:
float $diameter_barrel;
This command declares a variable of data type float, with the name
diameter_barrel. A floating point value is a number containing a decimal.
2 To assign a value to the variable, type the following.
$diameter_barrel = 4.2;
The diameter of the barrel is 4.2 units. This value from the scene is
assigned to the variable. A value is assigned to a variable with the
assignment operator (=).
Storing other types of data
MEL also supports other data types that are common to most other
programming languages.
To declare a string variable
Type the following in the Script Editor
string $testString = "this is a test";
print $testString;
The following is output to the Script Editor:
this is a test
The string data type is used to store multiple characters. The print
command outputs the value of a variable to the Script Editor.
NOTE Variables can be declared and assigned a value in the same statement.
676 | Chapter 13 Scripting in Maya