Inconsistency in mel?

Can sbdy please clarify the way mel
requires its variables be specified in statements
which are executed within quotes?

The following code gives me error
in line 5

string $sa[] = polySphere; //line 1
print $sa[0] ; //should print pSphere1, line 2
string $obj = $sa[0]; //line 3
float $v[]; //line 4
$v = pointPosition -w $obj.vtx[0]; //line 5
print $v; //line 6

This gives me the following error
// Error: line 5: Too many arguments. Expected 1, found 2. //

The error goes away if I use the following code in line 5.
$v = pointPosition -w pSphere1.vtx[0]; //line 5

How ever the following piece of
similar code doesnt give me any error.

string $sa1[] = polySphere;
print $sa[0];
float $v[];
$obj = $sa1[0];
$sa = polyListComponentConversion -fv -tuv $obj.vtx[0:4];

Note that I refer to pShere1 here by means of the variable $obj
and is still okay here, while it was not okay
in the first code.

-koshy

need to pass it as a string, so if you want to build string w a variable you gotta concatenate it
eg - ($obj + ".vtx[0]")

He's asking why it failed in the first example but then worked in the second one.

Frankly I'm baffled. I wouldn't have expected it to work in either case.

Campbell just explained it. The essence of mel scripting is building strings of mel commands with variables.

right, first time i decided to do a cut to the chase, but i been caught, there was more to the problem ...

which im mildly baffled about too! inconsistency, yeah.

perhaps some commands were built to accomidate this syntax because they couldnt be bothered building the strings all the time for such simple addressing for certain tasks.. dunno.

Not realy true... some things are considerer as objects such as sphere.tx but feeding it from a string wouldnt make it the same thing anymore!

its the difference between mel and expression syntax!

yep yep, we get that joojaa!

i think figured it. its that certain commands look to the current selectn to do their actn - " if obj not specified then works on selectn " kind of MO. what you'll find is that poly-type commands dont even give a flyers as to the variable infront of the component, it just looks at the slectn and the comp index ..... so if you have:

$obj = cube;
select -r torus;
polyExtrudeFacet $obj.f[4];

you'll extrude face 4 of the torus, the cube untouched. nice. so emit the $var (like it does), and set your sel before hand if you want to use it like that, else build your string to hand it. if you have nothing selected, it cant find the index on nothing.

pointPosition does have a bit more of a look at ts arguments, and thinks its trying to do two objects, which it doesnt like (same as other sel ctx commands) ... pointPosition $obj.vtx[2] returns the same error as if you did pointPosition .vtx[2] w two objs selected.

so, sorta inconsistant that some commands 'notice' the variable there and error, while others just think your a twit and move right along!

Ahh yeah well thats just bacuse some commands have default behaiviour and others dont! umm thenagain not in this case. (sorry im not in front of a maya so i cant test this right now)

but theres certainly seems something fishy with your script example (but ill try this at first hand)! try doing it inside a proc where the variables are explicitly defined since somethimes vars do carry over especialy if you type them in the script editor.