Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
To Nest or Not to Nest Else
#20
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.

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:
Reply


Messages In This Thread
To Nest or Not to Nest Else - by Dimster - 08-17-2024, 03:11 PM
RE: To Nest or Not to Nest Else - by SMcNeill - 08-17-2024, 03:35 PM
RE: To Nest or Not to Nest Else - by PhilOfPerth - 08-17-2024, 11:28 PM
RE: To Nest or Not to Nest Else - by TerryRitchie - 08-17-2024, 06:51 PM
RE: To Nest or Not to Nest Else - by Pete - 08-19-2024, 03:23 AM
RE: To Nest or Not to Nest Else - by Dimster - 08-19-2024, 07:30 PM
RE: To Nest or Not to Nest Else - by SMcNeill - 08-19-2024, 08:58 PM
RE: To Nest or Not to Nest Else - by Dimster - 08-19-2024, 09:08 PM
RE: To Nest or Not to Nest Else - by Pete - 08-19-2024, 09:52 PM
RE: To Nest or Not to Nest Else - by TerryRitchie - 08-19-2024, 10:05 PM
RE: To Nest or Not to Nest Else - by SMcNeill - 08-19-2024, 10:19 PM
RE: To Nest or Not to Nest Else - by TerryRitchie - 08-19-2024, 10:24 PM
RE: To Nest or Not to Nest Else - by Pete - 08-19-2024, 10:10 PM
RE: To Nest or Not to Nest Else - by TerryRitchie - 08-19-2024, 10:14 PM
RE: To Nest or Not to Nest Else - by SMcNeill - 08-19-2024, 10:30 PM
RE: To Nest or Not to Nest Else - by TerryRitchie - 08-19-2024, 10:35 PM
RE: To Nest or Not to Nest Else - by SMcNeill - 08-19-2024, 11:56 PM
RE: To Nest or Not to Nest Else - by Pete - 08-19-2024, 10:53 PM
RE: To Nest or Not to Nest Else - by luke - 08-20-2024, 11:17 AM
RE: To Nest or Not to Nest Else - by OldMoses - 08-20-2024, 12:06 PM
RE: To Nest or Not to Nest Else - by bplus - 08-20-2024, 01:40 PM
RE: To Nest or Not to Nest Else - by Dimster - 08-20-2024, 01:45 PM
RE: To Nest or Not to Nest Else - by bplus - 08-20-2024, 02:08 PM
RE: To Nest or Not to Nest Else - by Pete - 08-20-2024, 04:37 PM
RE: To Nest or Not to Nest Else - by dano - 08-20-2024, 10:54 PM
RE: To Nest or Not to Nest Else - by Pete - 08-20-2024, 11:39 PM
RE: To Nest or Not to Nest Else - by OldMoses - 08-22-2024, 05:28 PM
RE: To Nest or Not to Nest Else - by TerryRitchie - 08-22-2024, 06:45 PM
RE: To Nest or Not to Nest Else - by bplus - 08-22-2024, 05:41 PM



Users browsing this thread: 15 Guest(s)