CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-07-2003, 06:05 PM   #1
(B-HOLM)
Cg Dork
 
(B-HOLM)'s Avatar
 
Join Date: Sep 2002
Posts: 204
between

uhm I was wondering if there was a kind of between function...I have been looking for some stuff in the help docs, but haven't found anything

I wanna do like this



if (frame == between(1, 3)
{
do stuff
}


hope your understand :/
__________________
Highpoly human W.I.P
 
Old 04-07-2003, 06:26 PM   #2
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
proc int between (float $test, float $low, float $high)
{
int $return_val = (($test >= $low) && ($test <= $high));
return $return_val;
}



$frame = frame;

if (between($frame, 1, 3))
{
do stuff
}


This between procedure is inclusive, meaning that if $test equals $low or $high it comes back true.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators

Last edited by mark_wilkins : 04-07-2003 at 07:04 PM.
 
Old 04-07-2003, 06:53 PM   #3
(B-HOLM)
Cg Dork
 
(B-HOLM)'s Avatar
 
Join Date: Sep 2002
Posts: 204
sorry I wasn't clear enough...I meant that I wanted an interval function...
so that when the fram is equal to 1,2 and 3 then stuff would happen...did that clear it up?
__________________
Highpoly human W.I.P
 
Old 04-07-2003, 07:01 PM   #4
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
How is what you are requesting different than what I gave you?

In the example I posted, if the frame is 1, 2, 3, or anything in between, the contents of the if statement will execute. I'm not sure what else you want.

To be more clear, it is not possible to make the == operator test your frame number to determine whether it is within a range, but it is possible to test whether it is within an interval by using a function, and I have implemented a function to do this, which you will see above.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators

Last edited by mark_wilkins : 04-07-2003 at 07:03 PM.
 
Old 04-07-2003, 07:04 PM   #5
(B-HOLM)
Cg Dork
 
(B-HOLM)'s Avatar
 
Join Date: Sep 2002
Posts: 204
well, as I understand it then the thing you gave me is how to make a function that returnes the number between to numbers...
but what I want is something that like when :

if( frame == 1 - 5 ) //from 1 to 5
{
then do stuff
}
__________________
Highpoly human W.I.P
 
Old 04-07-2003, 07:06 PM   #6
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
Huh???

Using the function I defined above:

$frame = frame;
if (between($frame, 1, 5))
{
do whatever you want done when
the frame number is between 1 and 5,
inclusive.
}


The function I posted returns one (1) if the first argument $test is between $low and $high, and returns zero (0) if the first argument $test is not between $low and $high.

The if statement executes its contents if the between function returns 1 and skips the contents if the between function returns 0.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators

Last edited by mark_wilkins : 04-07-2003 at 07:09 PM.
 
Old 04-07-2003, 07:09 PM   #7
(B-HOLM)
Cg Dork
 
(B-HOLM)'s Avatar
 
Join Date: Sep 2002
Posts: 204
ok, well I'm sorry, guess I just misread your script I guess :thumbsdow
__________________
Highpoly human W.I.P
 
Old 04-07-2003, 07:10 PM   #8
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
it's OK.

Is it clear now or would more explanation help?

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 04-07-2003, 07:15 PM   #9
(B-HOLM)
Cg Dork
 
(B-HOLM)'s Avatar
 
Join Date: Sep 2002
Posts: 204
well, the only things I can't understand is:

1. why floats in the parameter?
2. what is the return for? been so long time ago since I've done anything with return :(
3. and well...I can't understand what the $test is for...is it what the function equals or is the return what the function equals....

I now I'm not very clear, 'cause my programming knowledge isn't great :/
__________________
Highpoly human W.I.P
 
Old 04-08-2003, 12:53 AM   #10
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
1) The values in the parameters are floats (short for floating-point numbers, or numbers with fractional parts) because frame numbers can be fractional. For example, you can set the timeline to 1.2 or 1.4. (Try it!)


2) When you define a function like this

proc int test (float $a, float $b, float $c)
{
(whatever)
}

that means that the procedure "test" will make a calculation using the values of $a, $b, and $c, and that the result will be an integer. To figure out whether one number is between two other numbers, you need three numbers: $test is the number you're checking, $low is the lower bound of the range, and $high is the higher bound.

3) If a procedure passes back a value to the expression that contains it (which the "int" in the declaration above says it will) then you need to use a return statement to tell it what to return. For example, if you use the procedure above like this:

print (test(1, 2, 4) + 3);

this print statement executes the test procedure. Whatever the return statement in that test procedure says to return becomes the value that gets added to 3, then the result of that addition gets printed out.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 04-08-2003, 01:55 PM   #11
(B-HOLM)
Cg Dork
 
(B-HOLM)'s Avatar
 
Join Date: Sep 2002
Posts: 204
hehe, I just took a look at it today, and I understand it all now. Must have been very tired yesterday hehe.
But Mark, once again thanks for all your help
__________________
Highpoly human W.I.P
 
Old 04-11-2003, 04:08 AM   #12
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
No problem!!!

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 01-14-2006, 09:00 PM   #13
CGTalk Moderation
Expert
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,478
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 10:12 AM.


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