View Full Version : between
04 April 2003, 06:05 PM
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 :shrug:
I wanna do like this
if (frame == between(1, 3)
hope your understand :/
04 April 2003, 06:26 PM
proc int between (float $test, float $low, float $high)
int $return_val = (($test >= $low) && ($test <= $high));
$frame = frame;
if (between($frame, 1, 3))
This between procedure is inclusive, meaning that if $test equals $low or $high it comes back true.
04 April 2003, 06:53 PM
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?
04 April 2003, 07:01 PM
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.
04 April 2003, 07:04 PM
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
04 April 2003, 07:06 PM
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,
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.
04 April 2003, 07:09 PM
ok, well I'm sorry, guess I just misread your script I guess :cry: :thumbsdow
04 April 2003, 07:10 PM
it's OK. :D
Is it clear now or would more explanation help?
04 April 2003, 07:15 PM
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 :/
04 April 2003, 12:53 AM
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)
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.
04 April 2003, 01:55 PM
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 :)
04 April 2003, 04:08 AM
01 January 2006, 09: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.