Page 1 of 1

plus or minus 10

PostPosted: Fri Jul 20, 2007 8:54 pm
by pixelpoop
is their a quick way to test a plus or minus instead of using &&?

a simple example of what I am looking for:
// if player's x position is more then or equal to -10 and less then or equal to 10 then do something.
if (player.x =+- (10))do something;

the longer way I know works:
if (player.x>=-10 && player.x<=10)do something;

PostPosted: Fri Jul 20, 2007 9:17 pm
by metal_pt
Well, you can always try:

Code: Select all
if(abs(player.x)<=10){
    do what you want it to do;
}


But I don't understand why you want to do that.

Regards

PostPosted: Fri Jul 20, 2007 10:00 pm
by Fuzzy
from what i read you want to test and do something if the number is BETWEEN -10 and 10?

Code: Select all
if (abs(player.x) < 11)
{
    do stuff here
}


is as simple as it gets.

PostPosted: Fri Jul 20, 2007 10:37 pm
by pixelpoop
you guys rock,
I forgot all about absolute values.

If anyone else forgot their math here is an easy definition from http://www.purplemath.com/modules/absolute.htm

absolute value is never negative; absolute value only asks "how far?", not "in which direction?"
The absolute value of -3 is 3, because -3 is 3 places away from 0.

PostPosted: Sat Jul 21, 2007 3:51 am
by Fuzzy
great definition.