View Full Version : conditonal based on multiple values...

06 June 2004, 01:15 PM
This one is probably pretty basic...but I'm new to mel :p ...Is there a way to check if multiple statements are true, and if so do something?

For example, I could say that:

float $der = 0;
if ($der == 0)
{print ("der is 0");};

but...say I wanted to add to that so that it checks the value of more than one variable. I know this next one isn't written right, but thats essentially my question, how to write it correctly so that I can check multiple variables and do something only if they are both true, or both false or bla bla bla... I was thinking along the lines of nested conditional statements...but they don't seem to be working correctly. I don't get a syntax error when I try them... but it doesn't evaluate correctly.

if (($der == 0) AND ($fred == 1))
{print ("der plus fred");}

else {do this};

Thanks for any help on this one

06 June 2004, 02:17 PM
I guess there would be different ways of doing this. One way would be like this:

if (($der == 0) && ($fred == 1))
print ("der plus fred");

Or like this:

if ($der == 0)
if ($fred == 1)
print ("der plus fred");

The later would be the "nested" approach. And hopefully you know exactly how many variables you need to check; otherwise you would need to use a recursive approach (to check an arbitrary number of variables).

06 June 2004, 09:28 PM
Thank you very kindly, you made my day :)

One other q for you or anyone else... is there a way to use the source command (that I understand isn't even a command at all)

string $roar = "jumbo";
string $der = ("menu_mod" + $roar);
source "$der";

Now...we have a problem. Maya is trying to source a Mel file that doesn't exist...its trying to source $menuName.mel, instead of sourcing the value that the variable $menuName contains.

Ideally it should be something like this...

string $roar = "jumbo";
string $der = ("menu_mod" + $roar);
print ($der);

but I can't seem to get "source" to read the value of the string, rather the name of the variable. I assumed this was because it was in quotes...but I get a syntax error whenever I rid myself of them :(

From what I understand "source" isn't even a Mel command...but a "directive" for what to compile and source, and the arguments for this can be paths, or filenames...but does this mean I can't derive a filename based on a variable?

If anyone knows how to do this...source a Mel file through a variable, that would rawk if you could share that information, or point me to a better way of doing this.

Thanks again for your help, man.

06 June 2004, 09:36 PM
Try this:

string $command = "source ";
string $roar = "jumbo";
$command = ($command + "menu_mod" +$roar);
$command = ($command + ".mel");
eval $command;

07 July 2004, 03:53 PM

Thanks man! Thats pretty cool btw, using the variables previous value and appending a new value to that...didn't know you could do that. ->mel newbie<- much to learn...


07 July 2004, 11:58 AM
Putting strings together like that is pretty common in MEL so it will become like second nature to you :)

As for my response, you need to put the string together and evaluate it, look up "eval" in the MEL command docs, should explain everything.

CGTalk Moderation
01 January 2006, 03:00 PM
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.