While loops - syntax errors? <.<

While loops - syntax errors? <.<

Anonymous
Not applicable
892 Views
9 Replies
Message 1 of 10

While loops - syntax errors? <.<

Anonymous
Not applicable
Ok, so this is what I want:

seperating the string into an array with the stringToStringArray cmd &#40;works fine&#41;
then I want the size of that array to be stored as an int in a seperate var (works fine as well)
Then I want a while loop so that maya returns me prints for every element in the array.(doesnt work. Here's the lines:


$gVar_ccN_spine = stringToStringArray($lVar_spineCtrlNames,";") ;

int $lVar_arraySize = `size $gVar_ccN_spine`; //write the size of the spineCtrl Array to a local variable named §lVar_arraySize
//----------------
//print check variables:
while ($counter=0; $counter <= $lVar_arraySize;$counter ++ )
{
print ("\n \n Updating $gVar_ccN_spine to:");
print $gVar_ccN_spine;
print "\n...done.";
}


MEL goes completely bananas and I have no clue why >_< I set the while loop up just as I would an IF function (which always work just fine) but somehow Mel keeps returning THREE syntax errors on the "while" line. Maybe I ddnt get enough sleep, maybe Im mentally handicapped, but I have no idea what on earth I messed up here.

So I beg you, tell me the obvious so I can facepalm myself to death. 😛
0 Likes
893 Views
9 Replies
Replies (9)
Message 2 of 10

lee.dunham
Collaborator
Collaborator
use a for instead, i seldom use while loops, preference really, hence the reason im not sure why it doesn't work but i'm guessing its the argument. i dont think you can use an arugument like you have (declaring what the iterarion is) on a while loop, use something like ;



$gVar_ccN_spine = stringToStringArray($lVar_spineCtrlNames,";") ;

int $lVar_arraySize = `size $gVar_ccN_spine`; //write the size of the spineCtrl Array to a local variable named §lVar_arraySize
//----------------
//print check variables:
int $counter = 0 ;
while($counter < $lVar_arraySize)
{
print ("\n \n Updating $gVar_ccN_spine to:");
print $gVar_ccN_spine;
print "\n...done.";
$counter ++ ;
}


instead. but personally, i'd stick to a for loop.
0 Likes
Message 3 of 10

Anonymous
Not applicable
thx ! works fine now.
however, im getting a new error on another line which I cant seem to figure out:

print ("\n \n Updating $gVar_ccV_transHip to:") ;

again a syntax error which I just don't understand. 😕
0 Likes
Message 4 of 10

lee.dunham
Collaborator
Collaborator
print ("\n \n Updating "+$gVar_ccV_transHip+" to:") ;


you were trying to print the raw var (ie print "$variable" ; will print "$variable") rather than what you want (so i think) which is to print the evaluation of the variable.

however i didnt get a syntax error like you said, which makes me wonder what the $variables are?

if they either vars are arrays, it wont work (illegal operation "+" on type string[] etc)
0 Likes
Message 5 of 10

Anonymous
Not applicable
Well, what I was trying to do was that it should basically "announce" the value that will be displayed (in this case $gVar_ccV_transHip). So it should pop up as:
"

Updating "Updating $gVar_ccV_transHip to:"
x being the value of $gVar_ccA_transCtrls.
0 Likes
Message 6 of 10

Anonymous
Not applicable
okay, so I've tried splitting it up in seperate print cmds like this:

print "updating $gVar_ccV_transHip to:";


And it now gives me the syntax error for the first line only.
So Im guessing it's the '[' there.
Do I have to put a special character in front of it? slashes won't work 😕

*edit*
Nevermind. Even when I remove the brackets it still gives me a syntax.


print "updating gVar_ccV_transHip";

print $counter;
print " to:";
// Error: print "updating gVar_ccV_transHip";
//
// Error: Syntax error //


*edit2*
Restart ftw!
NOT. I thought It worked, but as soon as I source the whole script it pops the syntax error again. This is driving me nuts. >_<
Is there any other way to have this displayed? like some magic cmd I dont know about? It doesnt even have to be visible for the user, I just need it to check if all my vars have been transferred correctly 😕
0 Likes
Message 7 of 10

Anonymous
Not applicable
Okay. Since the problem seems to be with mel on this one, for a change, Im just gonna try to omit the prints.
makes finding error a little more tedious, but im at a point where I just want this damn thing to at least source properly.

So I moved the procs that I had in one file and went through them seperately (makes things easier anyways) and commented the print cmds out.

Also, I replaced the while loop with the for loop as I once again got errors with the wile loop.
I replaced it with this:


for ($counter=0; $counter <3; $counter ++)
{
if ($counter != $gVar_ccA_transCtrls)
{
$gVar_ccV_transHip =($gVar_ccV_transHip * 0.1);
$gVar_ccV_transFoot =($gVar_ccV_transHip * 0.1);
}
}


However, THIS is what MEL now complains about:

// Error: for ($counter=0; $counter <3; $counter ++)
//
// Error: Syntax error //
// Error: for ($counter=0; $counter <3; $counter ++)
//
// Error: Syntax error //
// Error: for ($counter=0; $counter <3; $counter ++)
//
// Error: "$counter" is an undeclared variable. //
// Error: $gVar_ccV_transFoot =($gVar_ccV_transHip * 0.1);
//
// Error: "$counter" is an undeclared variable. //
// Error: }
//
// Error: Syntax error //


Now, when I define the variable before the for loop, it says thath its an undefined variable just a little more often.
I've tried restarting maya, but it doesnt make a difference. v.v
thx for helping me on this, and thx for ur patience with me v.v
0 Likes
Message 8 of 10

lee.dunham
Collaborator
Collaborator
lol no probs 🙂

first off, its good practice to show line number in errors, so you can pinpoint the line (saves so much time :))

just confirming that;

$gVar_ccV_transHip is either an int or float array
$gVar_ccV_transFoot is either an int or float array
$gVar_ccA_transCtrls is either an int or float

as long as those vars conform to the list above, i dont get those errors.

post up the vars and i'll have another check

//EDIT//
just had another look at what you said, i think you may have an issue with your maya, if not the commands. if possible to test a couple of things, try -

python ("print 'updating $gVar_ccV_transHip['") ;

and this one

eval&#40;"print \"updating $gVar_ccV_transHip[\""&#41; ;

if not. the first is printing in python called in mel, the second is to evaluate the line then execute (they both work here - but then, the original code did though).

have you recently installed the sp1 or sap?

it might be worth some more experienced guys to have a look.
0 Likes
Message 9 of 10

Anonymous
Not applicable
the _ccV_ vars are float Arrays, the ccA is an int yes.
I'll send you the scripts, I think that makes more sense ?
because It seems like my machine/maya is the problem. I havent installed anything recently, and it used to work perfectly. Also, sourcing wasnt a problem when I restarted the computer this morning, but after that it just ddnt work anymore (not even another restard).

Would that be ok with you? Its six files, and none of them has more than 100 lines ( and most of it are comments/prints) . I would really appreciate that. I'll have my collegues try the scripts as well, and if it should work with their maya, i guess ill just try re-installing.

**edit**
Oh and I ddnt even know that you had to turn line numbrs ON in the options to see them in errors. xD I always thought that would be awesome. thx for pointing that out 😄 ;D

Also, the eval(print doesnt work either. :<
0 Likes
Message 10 of 10

lee.dunham
Collaborator
Collaborator
no probs, i'll pm you now.
0 Likes