PDA

View Full Version : Undeclared Variable in for loop


CoreyJAvitar
04-17-2008, 05:14 PM
Hey Youall, silly question, but this has been driving me NUTZ!
I have this little script I wrote which imports references. It worked in Maya 7 on windows, but when I run this in Maya 2008 on Linux, it kicks back an error saying that $obj is not defined.


for( $i=0; $i<5; ++$i ){
$stringOfNames = `file -q -r`;
for ($obj in $stringOfNames){
file -ir $obj;
}
}


Any help would be great!
Thanks!

BPorter
04-17-2008, 05:50 PM
The only reason why you would need a "for-in" loop is if you have an array. $stringOfNames should be $stringOfNames[] in order for it to be necessary for the "for-in" loop. You could try getting rid of that code and just executing the import reference. I would have to see the rest of the code to understand the need for the "for" and "for-in" loops. I don't know if that helps at all, but as far as syntax goes that's the only thing I notice. Good Luck!

try:

for( $i=0; $i<5; ++$i ){
$filename = `file -q -r`;
file -ir $filename;
}

//////////////////////------------OR------------

for( $i=0; $i<5; ++$i ){
$stringOfNames[] = `file -q -r`;
for ($obj in $stringOfNames){
file -ir $obj;
}
}

//////////////////////------------OR------------

$stringOfNames[] = `file -q -r`;
for ($eachName in $stringOfNames){
file -ir $eachName;
}

CGTalk Moderation
04-17-2008, 05:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.