Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Martyn on Fri 18/09/2015 08:13:12

Title: x,y position +-1
Post by: Martyn on Fri 18/09/2015 08:13:12
Hello!

I have this code to check a x and y position, it works fine right now!

Code (ags) Select
oObject1.X == (Object2.X)) &&  oObject1.Y == (Object2.Y))

Have tested around, lik: oObject1 Is greater than or equal  and oObject1 Is less than or equal an +-
and so on.

Now my question, can I using "+ - < > and" to get the right y or x position and/or position= -1 or +1 (pixel). If y position = 3 so are 2 and 4 also true! I got it to work with "if" but can i also have it in a one line string as above?




Title: Re: x,y position +-1
Post by: Crimson Wizard on Fri 18/09/2015 09:50:29
Code (ags) Select

if ((oObject1.X >= Object2.X - 1) && (oObject1.X <= Object2.X + 1) &&
    (oObject1.Y >= Object2.Y - 1) && (oObject1.Y <= Object2.Y + 1))


This means: if object1.X is in range between (object2.X - 1) to (object2.X + 1), inclusive, same with Y.
Title: Re: x,y position +-1
Post by: Martyn on Fri 18/09/2015 10:13:44
man...I was close. Thanks Crimson Wizard!

Do i have some limit for how many, for exampel "&&" i can use in one line?
Title: Re: x,y position +-1
Post by: Crimson Wizard on Fri 18/09/2015 10:30:40
Quote from: Martyn on Fri 18/09/2015 10:13:44
Do i have some limit for how many, for exampel "&&" i can use in one line?
I am not sure if there is one. There might be some internal limitations in script compiler, but they are not too low, and should not bother you.
I split the text into 2 lines, because I find that easier to read.
Title: Re: x,y position +-1
Post by: Snarky on Fri 18/09/2015 10:43:56
(And just to avoid confusion, splitting an if-condition across multiple editor lines in this way doesn't make a difference to the compiler, either for better or worse. It's merely for the sake of human readability.)