Beginner having troubles

Started by
4 comments, last by King Mir 16 years, 1 month ago
Hi guys string axis = "x"; MPoint point; if (point.axis == 0) { } Simplified version of some maya api code,but you get the idea :) axis is the flag for the command and can be x,y or z.In this case it is set to x for demonstational purposes. This is the problem point.axis I can't do it like that,and i want if x is chosen to compare only x value of the point with some else.So how to do it? thank you
Advertisement
Quote:Original post by TheMan22
Hi guys

string axis = "x";
MPoint point;
if (point.axis == 0)
{
}

Simplified version of some maya api code,but you get the idea :)

axis is the flag for the command and can be x,y or z.In this case it is set to x for demonstational purposes.

This is the problem point.axis

I can't do it like that,and i want if x is chosen to compare only x value of the point with some else.So how to do it?

thank you
What's wrong with if (point.axis.x == 0)? What is "MPoint::axis"?
What does the local variable, "axis" have to do with anything?
MPoint does not have axis method.

axis is a variable and can get values x,y,or z.

MPoint has methods MPoint::x,MPoint::y and MPoint::z

So axis tells which one of those should be used,you understand now?

Quote:Original post by TheMan22
MPoint does not have axis method.

axis is a variable and can get values x,y,or z.

MPoint has methods MPoint::x,MPoint::y and MPoint::z

So axis tells which one of those should be used,you understand now?
Ah, I see. Then you'll want something like:
if(axis == "x" && point.x == 0){   // Whatever}else if(axis == "y" && point.y == 0){   // Whatever}else if(axis == "z" && point.z == 0){   // Whatever}

Assuming C++, that is. Also note that string comparisons are case sensitive.
no other way to do this ?

I must use if statements?

In mel for example you do this :

polyCube -name "some" // means create a 3d cube called some

And you can do something like this :

string $name = " -name ";
eval("polyCube" + $name + "\"some\"");


Quote:Original post by TheMan22
no other way to do this ?

I must use if statements?
The other solutions are to use a switch, a map, or both together. But the logic you have to program is the same; you have to manually map each possible input, with the proper code to execute.

Quote:In mel for example you do this :

polyCube -name "some" // means create a 3d cube called some

And you can do something like this :

string $name = " -name ";
eval("polyCube" + $name + "\"some\"");
That's because mel is apparently a scripting language. Scripting languages allow you to call variables by name. Compiled languages don't even store the names of variables in memory.

This topic is closed to new replies.

Advertisement