Chinaunix首页 | 论坛 | 博客
  • 博客访问: 140247
  • 博文数量: 54
  • 博客积分: 2147
  • 博客等级: 大尉
  • 技术积分: 530
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-19 21:14
文章分类

全部博文(54)

文章存档

2011年(6)

2010年(18)

2009年(9)

2008年(2)

2007年(13)

2006年(6)

我的朋友
最近访客

分类:

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.

string $words[] = {"a","bb","ccc","dddd","eeeee","ffffff"};
string $long = "";
for ($i = 0; $i < size($words); $i++){
 if (size($words[$i]) > 4){
   $long = $words[$i];
   break;
  }
print($words[$i] + " is too short...\n");
};
print($long + " is the first long word.\n");


阅读(451) | 评论(0) | 转发(0) |
0

上一篇:

下一篇:Nuke学习笔记

给主人留下些什么吧!~~