Mel - Maya Embedded Language

<HOME>   <PREVIOUS>   <NEXT>

Operators

Assignment Operator
Arithmetic Operators
Boolean Operators
Comparisson Operators
Logical Operators
Precedence

Assignment Operator

=
the equals sign sets a variable equal to a value. float $a = 2.135;

Arithmetic Operators

+
Add two elements
$C = $A + $B;

-
Subtract two elements
$C = $A - $B;

*
Multiply two elements
$C = $A * $B;

/
Divide two elements together
$C = $A / $B;

%
Find the fractional remainder of the division
$C = $A % $B;

Exercise: Make 2 polyCubes and name then cube1 and cube2. Create 2 variables to hold the widths. Edit the cubes to set the widths. Create a new cube that is the sum of the two widths (add them). Create another cube that is half of the width of cube1.

Boolean Operators

Booleans are used for making comparision and have one of two states: true or false. Booleans can be called using the following:
true, yes, on, 1
false, no, off, 0
Here are some examples using a boolean
$a = yes;
$b = false;

Comparison Operators

<
      less than
      A < B

>
      greater than
      A > B

<=
      less than or equal
      A <= B

>=
      greater than or equal
      A >= B

==
      equal to
      A == B

!=
      not equal to
      A != B

The relational operators are typically used in IF blocks and loops.

Logical Operators

Use logical operators when you want to compare two or more values.
||
      or
      a || b

&&
      and
      a && b

!
      not
      !a

In this example we use the not operator.
if (2 < 3) || (1 > 3)
{
      print "this is true";
}
else
{
      print "this is false";
}
In this example we use the and operator.
if (2 < 3) && (1 > 3)
{
      print "this is true";
}
else
{
      print "this is false";
}
In this example we use the not operator.
if !(5 < 3)
{
      print "this is true";
}
else
{
      print "this is false";
}
Here are examples using the and plus the or operator:
if(( 2 < 3 && 3 > 1 ) || ( 2>0 && 0>-1 ))
{
print "this is true";
}
else
{
print "this is false";
}
In this example we use the not operator.
if(!(5 < 3 && 3 > 1))
{
print "this is False";
}

Precendence

Precedence is the hierachy in which operators are evaluated. They are as follows:
( ), [ ] !, ++, --
*, /, %, ^
+, -
<, <=, >, >=
==, !=
&&
||
=, +=, -=, *=, /=

Included in this list are a few operators I have not covered.
+=, -=, *=, /=
This simply adds, subtracts, multiplys, or divides a variable by a given value and assigns the result back to the original variable.
$a += 5;
is the same as
$a = $a + 5;

++, --

This simply adds or subtracts by one and assigns it back to the original variable.
$a ++;
is the same as
$a = $a + 1;

<Top>