PDA

View Full Version : Abs value help.



Gleeok
11-19-2007, 04:12 AM
This has always confused me and I am still unsure of how to use it effectively.

Suppose I wanted an ffc script to trigger when Link is within 1 tile of the ffc in any direction. How would I do this using Abs(int x, int y)..?

If the ffc is at 48, 48 lets say, then if( (Abs(Link->X = this->X+8) >=24)&&(Abs(Link->Y = this->Y+8) >=24)){ It would trigger if link was closer than 16 pixels...?

...I really don't know how I came up with that just now.

DarkDragon
11-19-2007, 04:22 AM
I have no idea what that expression means; the inner part sets Link's X and Y coordinates, after which the compiler gives up because you can't take the absolute value of an assignment.

What you'd want is something like


if( Abs(Link->X - this->X) < 16 && Abs(Link->Y - this->Y) < 16)

which is true if Link is within 16 pixels of the FFC's position, ie, if Link is touching any part of the FFC's tile (assuming the FFC is 1x1).

Gleeok
11-19-2007, 04:48 AM
Yep, thats it. Wow, these will be great for custom bosses. Thank you! :)