PDA

View Full Version : Simple syntax question


TillKloeppel
08-15-2012, 11:57 AM
Hey, im kinda new to MEL so I run frequently into syntx errors.

My goal with this script is to load a variable ( here $OOProcArray[] ) into a procedure ( MyProcTest ) and execute the procedure when pressing a button.

If I press the button I get an error : "Wrong number of arguments on call to MyProcTest."

Any help/advice would be great ! =)


$ObjSel = `ls -sl`;

$OOProcX = `getAttr ($ObjSel[0] + ".tx")`;
$OOProcY = `getAttr ($ObjSel[0] + ".ty")`;
$OOProcZ = `getAttr ($ObjSel[0] + ".tz")`;

float $OOProcArray[] = {$OOProcX, $OOProcY, $OOProcZ};

proc MyProcTest ( float $OOProcArray[] ) {

print ( $OOProcArray[0] + $OOProcArray[1] );

}

if (`window -exists MYTESTWIN`) deleteUI MYTESTWIN;

window -title "My test Window" MYTESTWIN;

columnLayout;

button -l "test it" -c "MyProcTest()";

showWindow MYTESTWIN;


Greez, TK

djx
08-15-2012, 12:19 PM
The syntax error is because when you defined MyProcTest you specified that it should take a float array argument, but you do not supply that argument in the button command.

In your example you could make it work by rewriting like this

proc MyProcTest () {
string $ObjSel[] = `ls -sl`;
float $OOProcX = `getAttr ($ObjSel[0] + ".tx")`;
float $OOProcY = `getAttr ($ObjSel[0] + ".ty")`;
float $OOProcZ = `getAttr ($ObjSel[0] + ".tz")`;
float $OOProcArray[] = {$OOProcX, $OOProcY, $OOProcZ};

print ( $OOProcArray[0] + $OOProcArray[1] );
}

if (`window -exists MYTESTWIN`)
deleteUI MYTESTWIN;
window -title "My test Window" MYTESTWIN;
columnLayout;
button -l "test it" -c "MyProcTest()";

showWindow MYTESTWIN;


The alternative is to change the button command and supply the float array as specified when you declared the proc.

David

TillKloeppel
08-15-2012, 12:35 PM
Hey, thanks for the fast reply!

Maybe I wasn't clear about this ...

The goal is to

- define a variable ( in that case the float array)

- then load it into a procedure (e.g. proc MyProc (myFloatArray) )

- then use the variables from outside the procedure everytime i press the button in the procedure

I also tried to define the button command (-c) to something like this

button -c "MyProc (float $myFloatArray[])";

... but it still gets me that error =/

ldunham1
08-15-2012, 07:10 PM
you were almost there. You had the right idea in sending the variable as an arguement to the proc, the problem is how your sending it.
You want the value to be evaluated, stored in the variable and then inserted in the string to be called.
What you want should be this;
button -l "test it" -c ("MyProcTest({"+$OOProcArray[0]+","+$OOProcArray[1]+","+$OOProcArray[2]+"})");
you dont stick the variable in as a string if you want the value of the variable used. Also as it is an array, mel will complain that you can't use "+" with it so instead format it inside the proc, i chose to explicitly add each of the array items (tons of ways to do this.)

CGTalk Moderation
08-15-2012, 07:10 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.