Maya MEL 变量声明和初始化

Maya MEL variables declaration and initialization

在 MEL 中是否必须在声明变量时初始化变量,尤其是字符串?

我知道没有必要初始化字符串数组:

string $buffer[];
$buffer[0] = "abc";

但是字符串和其他变量类型呢?是否可以接受:

string $str;
$str = "abc";

还是应该始终使用双引号来初始化它?

string $str = "";
$str = "abc";

As a general rule, it is best to explicitly declare the type of a variable when it is defined. This ensures that you aren't depending on Maya to automatically determine the variable type for you.

来自 Complete Maya Programming 1

使用string $str;

您不需要填充变量,使用类型声明对其进行初始化会将其设置为默认值(整数为 0,浮点数为 0.0,字符串为 "")。一般来说,当初始变量有意义时,最好就地分配:

string $topCamera  = "|top|topShape";

但是当你需要占位符但还没有值时声明一个空变量是可以的;

int $cameraCount;
// make some cameras here;
$cameraCount = size(`ls -type camera`);

在该示例中将 $cameraCount 声明为 0 并没有坏处,但这只是额外的输入。

在此处插入强制性警告以了解 python