x,y position +-1

Started by Martyn, Fri 18/09/2015 08:13:12

Previous topic - Next topic

Martyn

Hello!

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

Code: ags
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?





Crimson Wizard

#1
Code: ags

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.

Martyn

#2
man...I was close. Thanks Crimson Wizard!

Do i have some limit for how many, for exampel "&&" i can use in one line?

Crimson Wizard

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.

Snarky

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

SMF spam blocked by CleanTalk