Some of the most common practices in Mel Scripting includes checking if something is true or false.
Or, in other words, how do you simply ask Maya a question? The answer is: "conditional statements".
Conditional statements use symbols to tell the computer if a value is or isn't equal to another value. These symbols are called "Comparison Operators"
Comparison Operators in Mel Script:
<
LESS THAN
A < B
"A" is less than "B"
>
GREATER THAN
A > B
"A" is greater than "B"
<=
LESS THAN OR EQUAL
A <= B
"A" is less than or equal to "B"
>=
GREATER THAN OR EQUAL
A >= B
"A" is greater than or equal to "B"
==
EQUAL TO
A == B
"A" is equal to "B"
!=
NOT EQUAL TO
A != B
"A" is not equal to "B"
Here are some examples of what we mean by "conditional statements":
IF
int $a = 10;
if ($a == 10) {
print "variable equals 10.\n";
}
IF/ELSE
int $a = 0;
if ($a < 10) {
print "condition is true.\n";
}
else {
print "condition is false.\n";
}
IF/ELSE IF
int $a = 8;
if ($a < 10) {
print "less than 10.\n";
}
else if ( ($a >= 10 ) && ( $a < 20) ) {
print "greater than or equal to 10 but less than 20.\n";
}
else {
print "greater or equal to 20.\n";
}
NESTING IF STATEMENTS
int $a = 2;
if ($a < 10) {
print "less than 10.\n";
if ($a < 5) {
print "also less than 5.\n";
}
}
SWITCH
int $a = 0;
switch ($a) {
case 1:
print "equals 1\n";
break;
case 5:
print "equals 5\n";
break;
case 10:
print "equals 10\n";
break;
default:
print "didnt match any above\n";
break;
}
No comments:
Post a Comment