Sign in to follow this  
TheMan22

Beginner having troubles

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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\"");


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this