You can write a function to make things less tedious to write:
'This function takes the XY coordinates of the top-left
'corner of the panel, and its width and height in pixels,
'and returns whether or not it's being touched currently
DEF TOUCHING(X,Y,W,H)
VAR TX,TY,TM
TOUCH OUT TX,TY,TM
RETURN TM && TX>=X && TX<X+W && TY>=Y && TY<Y+H
END
'If touching a 30x30 pixel panel at coordinates (50,100)...
IF TOUCHING(50,100,30,30) THEN
...
ENDIF
As a side note, when combining conditions like `X>100` and `X<200`, it's better to use `&&` and `||` instead of `AND` and `OR`.
This is because `AND` and `OR` are actually bitwise operators, whereas `&&` and `||` are logical operators, and there are subtle differences between them.
For example, they are different when either side is a number that isn't 0 or 1.
- With the logical operators, they treat 0 as false, and any other number as true.
For example, `7 && 10` is 1, because both 7 and 10 are not 0.
- With the bitwise operators, they compare each bit of the left number against each bit of the right number, and the result is all of the bit comparisons together.
For example, `7 AND 10` is 2, because in binary, 7 is 0111 and 10 is 1010, and the result is 0010 or 2 because that's the only bit set in both numbers.
Furthermore, logical operators will only evaluate the right side if necessary. For instance, with `0 && FUNC()`, `FUNC()` will not be executed because the answer would be 0 no matter what. Bitwise operators always evaluate both sides.
So, you can see that the bitwise operators are a lot more niche than the logical operators. Typically you'll only want to use bitwise operators with `BUTTON()`. For example, you can check if the A button is being held down like this:
IF BUTTON() AND #A THEN
...
ENDIF