I am trying to insert several conditions into an if statement as the following:
if a-n <= x <= a+n and b-m <= y <= b+m then … end (x,y,a,b are variable integers and n,m are constant integers)
But I can’t. Are there any type of conditional that I can use in this way without creating a loop?
I would hope changing it to:
if a-n <= x and x <= a+n and b-m <= y and y <= b+m then
would work.
Ignatz
March 26, 2013, 11:10am
3
if math.abs(x-a)<=n and math.abs(y-b)<=m then
Thanks Ignatz, that solved it.
Space monkey I had tried that but I guess you can’t use more than one and in if statement.
I don’t think there’s any limit to the number of and’s or or’s you can have in an if statement. I just tried 4 and’s which is one more than used here and it worked just fine.
Sorry it is my mistake, there’s no limit to ands as you say, somehow I wasn’t successful in my first try, probably I had done something else wrong…