plus or minus 10

Non-platform specific questions.

plus or minus 10

Postby pixelpoop » Fri Jul 20, 2007 8:54 pm

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;
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby metal_pt » Fri Jul 20, 2007 9:17 pm

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
]v[eta[_ - Using GE since June, 15 2007
Currently using v1.3.8 Registered
metal_pt
 
Posts: 117
Joined: Sat Jun 16, 2007 12:57 pm
Location: Sintra, Portugal
Score: 2 Give a positive score

Postby Fuzzy » Fri Jul 20, 2007 10:00 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby pixelpoop » Fri Jul 20, 2007 10:37 pm

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.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby Fuzzy » Sat Jul 21, 2007 3:51 am

great definition.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest