Subject: Programming Studio 1. 5.08.2014
What is an 'if' statement?
The If statement alternatively referred to as a conditional expression or a conditional statement is a statement that checks if a predetermined / defined condition is true or false.
Some modern programming languages allow different data types to be stored in lists and arrays (sequences). These are broken down into two distinctive catagories: 1. Homogenous. 2. Heterogenous. MEL can only support the homogenous approach which must contain the same type of data (eg: ALL string). Heterogeneous: can include different types of data.
Operator Precedence. Operators are '+' '-' and '*' Note: You always have to wrap equations in normal brackets. [like normal maths, you have to use brackets to create a specific order of operations].
Creating 'if' statements.
Eg: if ( 8 == 8 ) { print "yes this is true" }
Double >> arrows will run everything in the complete script and will never remove it as it does so. Single > arrows will delete your whole script if you have nothing selected. Be very careful, only use the single key if you want to run just a selection of code.
'Else' statements are very much like 'if' statements. They both need the curly brackets. Eg: if ( 6 > 8 ) { print "yes this is true" } else { print "no this is not true" }
You can also stack if statements - to create a really complex elimination sequence.
Your basic syntax for an 'if and else' statement of code is this: if ( // condition ) { // if true } else // condition { // if false }
Loops. A loop is a sequence of instructions that is continuously repeated until a certain condition is reached.
'For loop example' is the most common, easily used method.
'While loop' - Uses the same syntax as the 'if' statement. Eg: while ( 6 < 10 ) { print "something" } -Now because 6 is always less than 10, it continuously tests Maya for this. This will crash Maya badly. D:
$counter = counts the number of loops.
"++" '$counter++' This means to '+1'. It adds to the existing value. They are both the same, '++' just uses less code.
'For loop' example. For ($i = 0; $i < 10; $i ++) //initialise counter ; set max ; add 1. { print ("Hello World!" + $i + "/n"); // print Hello World! and add the current iteration value. }
$ - the dollar sign assigns something as a variable within the text.
You can also look up mel commands under the help files. Linear = a float in world space.
Making stairs example float $stairWidth = 10; float $stairHeight = 1; float $stairDepth = 1; int $stairAmount = 25;
Make sure you declare these before you keep going with the coding. The spaces and clear labels allow for effective readability.
Now... for ($i = 0; $i < $stairAmount; $i ++) { polyCube -w $stairWidth -h $stairHeight -d $stairDepth -n "step#"
xform -translation 0 ($stairHeight * $i) ($stairDepth * $i); }
window -tile "stair master"; columnLayout; floatfieldGrp -numberOfFields 1 -lable "stairWidth";
***Saved in week 2 file.










