Public Group

# Beginner having troubles

This topic is 3794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Quote:
 Original post by TheMan22Hi guysstring 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.axisI 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 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 on other sites
Quote:
 Original post by TheMan22MPoint 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::zSo 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 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 on other sites
Quote:
 Original post by TheMan22no 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 someAnd 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.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002040
×