global proc randomTY() { string $list[] = `ls -tr -sl`; int $size = size($list), $i; if ($size > 0) for($i = 0; $i < $size; $i++) setAttr ($list[$i] + ".ty") (rand(1,9)); }
// Define a global procedure called randomTY which takes nothing as input global proc randomTY() { // Define a string array variable $list[] and store a list of selected transform nodes in it string $list[] = `ls -tr -sl`; // Define an integer variable $size and store the size of the $list[] array in it. // Also we define another integer variable $i for later use. int $size = size($list), $i; // If there is something in the $list[] then go on. Otherwise just quit if ($size > 0) // Iterate though the list ($i goes from 0 to $size - 1) for($i = 0; $i < $size; $i++) // Set the .translateY (aka .ty) attribute of each object in the list to a random value of 1-9 // Note the extra parenthesis'. They are needed so the clauses inside gets executed first before the setAttr command. setAttr ($list[$i] + ".ty") (rand(1,9)); // End of story }
The solution can be ALMOST that simple. There's no reason to check the size of the array or loop by index. A for-in loop does that all for you:translateY = rand (1-9);
global proc randomTY() { string $sel_list[] = `ls -tr -sl`; for ($curr_sel in $sel_list) { setAttr ($curr_sel + ".ty") (rand(1, 9)); } }
Hehe, can you see the paranoid C programmer in me? :pOriginally posted by mark_wilkins
[B]There's no reason to check the size of the array or loop by index. A for-in loop does that all for you:
Dunno... to me it looks ok, no quote marks whatsoever...Also, what's up with the quote marks at the beginning and ending of a block of code? Is that a vBulletin thing??