View Full Version : Procedure that returns a boolean

11 November 2012, 02:20 PM
Ok this is confusing.
So MEL doesn't really have a boolean variable type - but you can create booleans by just ignoring the variable type in the declaration, like this:
$variable = false;

This got me thinking about procedures that returns booleans. How exactly are they written?
If I want a procedure to return a float for me, I have to write the procedure like this:

global proc float[] procedure()
global float $returnVal[];
// Some code
return $returnVal;

So how exactly do you return a boolean when it's not even a valid variable type?
Coz this just does not work:

proc procedure()
global $bool = false;
// Some code
return $bool;
...because Maya complains that the procedure does not have a return value.

I want to create some procedures that does some selection queries - and if my selections are "valid", these procedures will return a boolean with a value of "true". My other procedures will then only "work" if this returned boolean is true (ie: If the selection is faulty, the procedure won't fully execute).

The reason for this is just to keep down the amount of code. I don't want to have a ton of lines with code everytime I need to query the selection in my procedures. It's more "neat" if I can just call on another procedure (a selection query procedure) that then returns a bool for me, telling me if the selection is valid or not.

11 November 2012, 02:29 PM
Nvm, fuck it.
I'll just write the procedure so that it returns an int instead -_-
Seems like less of a hassle that way...

11 November 2012, 02:41 PM
Return an int value of 0 or 1. Where 0 == false and 1 == true. (Actually any value other than 0 is considered true). This is the expected approach and is used in other languages that don't have a boolean type (like C).

You can also use the int value directly in an if statement (similar to how you might use a boolean):
global proc int alwaysFalse() {
return 0;

global proc int alwaysTrue() {
return 1;

if (alwaysTrue())
print ("True\n");

if (!alwaysFalse())
print ("False\n");

11 November 2012, 08:48 AM
Nvm, fuck it.


In Maya you are supposed to use the "0/1 int" as a boolean....

CGTalk Moderation
11 November 2012, 08:48 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.