I was not aware of _ANDALSO, so there's a new toy to play with. Thanks for that heads up Luke.
I'll just leave this out here as the way I typically check for a value falling in a rectangular range.
In fact, I also combine two InRange% calls into a second function called InRegion% then only call that with all parameters in a single call. I find it highly readable that way. Only both InRange% results of TRUE will result in a TRUE InRegion% result.
FUNCTION InRegion% (xpos%, ypos%, xl%, xh%, yl%, yh%)
InRegion% = -(InRange%(xpos%, xl%, xh%) * InRange%(ypos%, yl%, yh%))
END FUNCTION
To reduce parameter count, I frequently set up click fields with a UDT array that contains upper left and lower right x/y data for all screen click points, then just ship off the UDT in an array loop to InRegion%, which then passes the appropriate data to the two InRange% calls. Once set up, click field recognition is a snap.
I'll just leave this out here as the way I typically check for a value falling in a rectangular range.
Code: (Select All)
SCREEN _NEWIMAGE(640, 480, 32)
$COLOR:32
DO
CLS
LINE (100, 100)-(200, 200), Red, BF
LINE (300, 100)-(400, 200), Blue, BF
LINE (500, 100)-(600, 200), Green, BF
WHILE _MOUSEINPUT: WEND
x = _MOUSEX: y = _MOUSEY
SELECT CASE x
CASE 100 TO 200
SELECT CASE y
CASE 100 TO 200
_PRINTSTRING (130, 140), "Pete!"
END SELECT
END SELECT
IF x < 300 THEN
ELSEIF x > 400 THEN
ELSEIF y < 100 THEN
ELSEIF y > 200 THEN
ELSE
_PRINTSTRING (330, 140), "Steve"
END IF
IF InRange%(x, 500, 600) THEN
IF InRange%(y, 200, 100) THEN ' Note: range order can be swapped
_PRINTSTRING (530, 140), "OldMoses"
END IF
END IF
_LIMIT 30
_DISPLAY
LOOP UNTIL _MOUSEBUTTON(1)
'Checks if a value (var&) is between (ll&) & (ul&) (order insensitive). Returns -1 if true 0 if false
FUNCTION InRange% (var&, ll&, ul&)
a& = -ll& * (ll& <= ul&) - ul& * (ll& > ul&) ' Boolean swap & ByVal protection
b& = -ul& * (ll& <= ul&) - ll& * (ll& > ul&)
InRange% = -((var& >= a&) * (var& <= b&)) ' in range? T/F
END FUNCTION 'InRange%
In fact, I also combine two InRange% calls into a second function called InRegion% then only call that with all parameters in a single call. I find it highly readable that way. Only both InRange% results of TRUE will result in a TRUE InRegion% result.
FUNCTION InRegion% (xpos%, ypos%, xl%, xh%, yl%, yh%)
InRegion% = -(InRange%(xpos%, xl%, xh%) * InRange%(ypos%, yl%, yh%))
END FUNCTION
To reduce parameter count, I frequently set up click fields with a UDT array that contains upper left and lower right x/y data for all screen click points, then just ship off the UDT in an array loop to InRegion%, which then passes the appropriate data to the two InRange% calls. Once set up, click field recognition is a snap.
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
sha_na_na_na_na_na_na_na_na_na: