Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / ABS command

Author
Message
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 1st May 2005 04:50
Well, not to sound like an idiot, but can anyone explain this command to me? I've seen it in even the simplest games like some of the pog sources floating around, and the help file that comes with DBPro didn't really help me much. I'm not much of a mathematical person and I'm asumming it must be some kind of math involved command, but I'd like to understand this command better and what kind of ways I can apply it. Thanks in advance!
Killonyas Slayer
19
Years of Service
User Offline
Joined: 13th Apr 2005
Location: Mozerok,Eartreg
Posted: 1st May 2005 10:38
As long as you know what an absolute value is, it's simple.

if you want something to happen by just the positive difference of two values.

say you want a ball to go back to the center of the screen in pong if it gets too far away from the paddle.

there are also many other reasons for it (this is just the only reason i know).

If you need any more help, just ask.
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 1st May 2005 22:47
Basically if you abs() as positive number it will remain positive if you abs() a negative number it will come back positive.
Thats it!....it can be very useful though, time splitter gave a neat example above.

Vixen
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location: Netherlands
Posted: 2nd May 2005 02:36
Try this:

I think that will clear it up for you

Trying to help where I can [Newbie status ]
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 2nd May 2005 05:30
I think I get it, so basically it just returns the positive value of a negative number so for like pong, if the ball is travelling in the negative X direction and it hits a certain point such as a wall it will reverse the direction by abs() the negative direction it was heading?

In this example you gave me "if ABS(p1p#-ballx#)>50", is that saying if the difference between the player and the ball is greater than 50, it will return the ball to the center of the screen, but you use the abs() to determine if its going in the negative direction to give you the positive movement back? Hope I made sense and I'm understanding this. Maybe a few more simple examples that I can actually run real quick might help me grab a full understanding but I think I get the basic idea.
thinkdigital
20
Years of Service
User Offline
Joined: 18th Oct 2003
Location:
Posted: 2nd May 2005 11:45 Edited at: 2nd May 2005 11:46
What they're saying in that command (if ABS(p1p#-ballx#)>50) is this:
First, it's the player's position - the ball's position
-or-

p1p#-ballx#

Then, they use absolute value on it. Why? Because that math operation could turn out a negative or positive number.

So if the player's position (p1p#) is below the ball's, and I'm thinking on the Y axis her then the value will always be positive right? Sure.
But if the player's position is above the ball's, then the answer would be negative.
Now what we're trying to find out is how far away the ball is right? Now, if the answer is positive, and the player's position is below that of the ball, then if p1p#-ballx# > 50 works just fine. However, observe that if the player's position is above that of the ball, even if it was say 50 pixels away (which is what we want to find out), the value would be -50, not 50.
So then we apply ABS() to the calculation - if ABS(p1p#-ballx#)>50 - so that if the player is below the ball, ABS won't do anything, because the result is already positive. But if the player is above the ball, it will turn -50 into 50, which would find the actual distance in pixels between the ball and the player, in any direction, up or down.

Hope I make any sense.

[b]eGeneric Works : Dark Basic Developer Website
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 2nd May 2005 12:00
Thumbs up for the explanation Makes much more sense now you explained it. Thanks again thinkdigital

Login to post a reply

Server time is: 2024-09-23 19:31:38
Your offset time is: 2024-09-23 19:31:38