CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 11-11-2012, 02:20 PM   #1
DeadlyNightshade
Plz...
 
DeadlyNightshade's Avatar
portfolio
Martin Dahlin
Jr. Technical Artist
King
Stockholm, Sweden
 
Join Date: Jul 2012
Posts: 892
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:

Code:
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:

Code:
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-11-2012 at 02:24 PM.
 
Old 11-11-2012, 02:29 PM   #2
DeadlyNightshade
Plz...
 
DeadlyNightshade's Avatar
portfolio
Martin Dahlin
Jr. Technical Artist
King
Stockholm, Sweden
 
Join Date: Jul 2012
Posts: 892
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.
 
Old 11-11-2012, 02:41 PM   #3
zeroeffect
Code Junkie
portfolio
Chris Zurbrigg
Software Developer
Independent
Canada
 
Join Date: Jul 2005
Posts: 213
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):
Code:
global proc int alwaysFalse() { return 0; } global proc int alwaysTrue() { return 1; } if (alwaysTrue()) print ("True\n"); if (!alwaysFalse()) print ("False\n");
 
Old 11-12-2012, 08:48 AM   #4
sciLoop
Expert
 
sciLoop's Avatar
portfolio
Burkhard Rammner
sciloop
Hamburg, Germany
 
Join Date: Sep 2008
Posts: 479
Quote:
Originally Posted by DeadlyNightshade
Nvm, fuck it.


;-----]

In Maya you are supposed to use the "0/1 int" as a boolean....
 
Old 11-12-2012, 08:48 AM   #5
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:53 AM.


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