Read-only archive of the Armageddon Games Forums Archive (2000–2026) · About this archive

Abs value help.

2 replies · 1,435 views · Started 19 November 2007

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.

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).