So I broke down my if statements to see if that worked. Unfortunately the same issue arose. So I went back to my original set of if statement.
`Checking overlapping boxes
for x = 1 to 3
for y = 1 to 3
`there is no need to check when y and x are the same
if not (x=y)
`check weather left side of box or right side of box is inbetween right and left side of other box
if (boxes(X,1)<boxes(y,1) or boxes(x,1)<boxes(y,3)) and (boxes(x,3)>boxes(y,1) or boxes(x,3)>boxes(y,3))
`checks wheather top of the box or bottom of the box is inbetween top and bottom of other box
if (boxes(x,2)<boxes(y,2) or boxes(x,2)<boxes(y,4)) and (boxes(x,4)>boxes(y,2) or boxes(x,4)>boxes(y,4))
`print "box ",x," over box ",y
overlap(x,y) = 1
endif
else
overlap(x,y) = 0
endif
endif
next y
next x
for x = 1 to 3
for y = 1 to 3
set cursor x*20,y*20
print overlap(x,y)
next y
next x
As 'Lost in Thought' pointed out (thanks again) that when the boxes move over each other from side to side it works correctly but not from bottom or top. I realized that these two actions were dealt with by separate 'if' statements. I then realized that I only had one 'else' statement so I added a second 'else' statement as shown below,
`Checking overlapping boxes
for x = 1 to 3
for y = 1 to 3
`there is no need to check when y and x are the same
if not (x=y)
`check weather left side of box or right side of box is inbetween right and left side of other box
if (boxes(X,1)<boxes(y,1) or boxes(x,1)<boxes(y,3)) and (boxes(x,3)>boxes(y,1) or boxes(x,3)>boxes(y,3))
`checks wheather top of the box or bottom of the box is inbetween top and bottom of other box
if (boxes(x,2)<boxes(y,2) or boxes(x,2)<boxes(y,4)) and (boxes(x,4)>boxes(y,2) or boxes(x,4)>boxes(y,4))
`print "box ",x," over box ",y
overlap(x,y) = 1
else
overlap(x,y) = 0
endif
else
overlap(x,y) = 0
endif
endif
next y
next x
for x = 1 to 3
for y = 1 to 3
set cursor x*20,y*20
print overlap(x,y)
next y
next x
and it now works.
Just thought I'd write it up if anyone was interested.
JC