PDA

View Full Version : variable not accepted


revilo3D
07-06-2006, 01:43 PM
hi guys, just trying to get past the whole copy and paste of mel and write something of my own however am really confused by something.

when i create a vector variable.. for example

vector $vertposition = <<1,2,3>>
// Result: <<1, 2, 3>> //
this is totally fine.. but if its called
vector $vertpos = <<1,2,3>>
it spits out this..
// Error: vector $vertpos = <<1,2,3>>; //
// Error: Invalid redeclaration of variable "$vertpos" as a different type. //

what is the wrong here :(. From what ive learnt so far im not breaking any rules of a variable.. i dont think. This is the second occurance is 45 mins of trying to create a script that ive run into this :(

also im trying to do put this data into a vector variable, but is proving to be over my head it seems..

xform -query -worldSpace -translation `ls -sl`

Any help would be wicked on with of these..

isoparmB
07-06-2006, 02:40 PM
You may have already delcared $vertpos as a different type of variable. If you close maya now, reopen and declare it as a vector, you will get the result you want.

You can redelclare a variable as a different type if you redeclare it in another bloc []. This is because of variable scope. If you declare $vertpos as an integer in a particular scope, and redeclare it as a vector later on, you will not be able to do so in that particular scope context.

Also, `ls -sl` will return a string array, so your code should be, assuming you have one object selected:

float $pos[];
string $sel[] = `ls -sl`;
$pos = `xform -query -worldSpace -translation $sel[0]`;
print $pos;

revilo3D
07-07-2006, 12:15 AM
oh great :) thanks man. I think I see how i ran into that problem.

I realise ls -sl is a string, but with the xform form is spittting out something that looks like a vector, yet I see you have put it in a float array, why?

thanks again :)

isoparmB
07-07-2006, 02:09 AM
It's ok to put it in a vector, too. Though I find it easier to put it in a float array, it's easier to access the individual elements from there than it is with a vector.

CGTalk Moderation
07-07-2006, 02:09 AM
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.