Procedure that returns a boolean

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  11 November 2012
Post Procedure that returns a boolean

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.
__________________
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.

Last edited by DeadlyNightshade : 11 November 2012 at 02:24 PM.
 
  11 November 2012
Nvm, fuck it.
I'll just write the procedure so that it returns an int instead -_-
Seems like less of a hassle that way...
__________________
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
 
  11 November 2012
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
Originally Posted by DeadlyNightshade: Nvm, fuck it.


;-----]

In Maya you are supposed to use the "0/1 int" as a boolean....
 
  11 November 2012
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:48 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.