分类:
2010-04-26 14:18:44
Code | Character |
\" | quotation mark |
\n | newline |
\t | tab |
\r | carriage return |
\\ | backslash |
Implicit type conversion
Maya automatically converts numbers to strings or vice versa when you use them together and it’s obvious what you meant.
Be careful: some cases are ambiguous, and what MEL chooses to do may not be what you meant. For example:
print("500" + 5);
Prints: 5005 (the string "500” with the string “5” added on the end), not 505 (the number 500 plus 5).
If you assign a value that does not match the type of the variable, the MEL interpreter will try to convert the value into the variables type.
For example:
// Declare the variables...
float $foo;
float $bar;
int $baz;
// Now assign values...
$test = 5.4;
// value of $test is 5.4
$bar = $test + 2;
// value of $bar is 7.4
$baz = $bar;
// the value of $baz is 7
// MEL converted the value to an integer.
An assignment evaluates as the assigned value.
//取整数只要给浮点输出值定义一个整数型变量即可
Note MEL does not support assigning string attributes to strings in statements like:
string $str = foo.str
Use this instead:
string $str = `getAttr foo.str`;
Convenience assignment operators
The following type of expression occurs often when you are programming:
$x = $x + 1;
This is so common that MEL provides several convenience operators to accomplish this with less typing. For example:
$x++ // adds 1 to the value of $x
$x-- // subtracts 1 from the value of $x
$x += 5 // adds 5 to the value of $x
$x -= 3 // subtracts 3 from the value of $x
Arrays are only one dimensional
Arrays can only hold scalar values. You cannot create an array of arrays. However, you can use the matrix datatype to create a two-dimensional table of floating point values.
Use the size function to get the size of an array:
string $hats[3] = {"blue", "red", "black"};
print(size($hats)); // 3
Use the clear function to free the memory used by an array and leave it with zero elements.
string $hats[] = {"blue", "red", "black"};
clear($hats);
print(size($hats)); // 0
Break
This example finds the first value in a string array that is longer than 4 characters.
|