while: wend
#12
(01-04-2023, 01:55 AM)bplus Wrote: No sooner did I post the edit when I tried the opposite:
10 If _MouseInput Then GoTo 10

They both freak'n worked!

Dang It looks like you just have to call _MouseInput, no loop needed! No GOTO needed nutt'n but a mention of _MouseInput!

Code: (Select All)
_Title "Click to draw paths from one click to next" 'b+ 2023-01-03

Do
    z = _MouseInput
    mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
    Locate 1, 1: Print mx, my
    If mb Then
        If lastx <> 0 And lasty <> 0 Then
            Locate my, mx: Print "X";
            If mx > lastx Then
                While lastx < mx
                    lastx = lastx + 1
                    Locate lasty, lastx: Print "X";
                Wend
            Else
                While lastx > mx
                    lastx = lastx - 1
                    Locate lasty, lastx: Print "X";
                Wend
            End If
            If my > lasty Then
                While lasty < my
                    lasty = lasty + 1
                    Locate lasty, lastx: Print "X";
                Wend
            Else
                While lasty > my
                    lasty = lasty - 1
                    Locate lasty, lastx: Print "X";
                Wend
            End If
        End If
        lastx = mx: lasty = my
    End If
Loop

What you have here is bad code.  Let me illustrate why rather simply:

Code: (Select All)
Do
    z = _MouseInput
    If oldX <> _MouseX Or oldY <> _MouseY Then Print _MouseX, _MouseY
    _Limit 60
    oldX = _MouseX: oldY = _MouseY
Loop Until _KeyHit

Drag the mouse around a bit.  Stop dragging.  How long does it take for your program to process all those mouse reports after you've finished moving your mouse??

Now, I know someone will say, "Yeah, but just increase your limit!!"

And SUUUURRREEEE, that might work for this specific example, but start *doing* something.  Write a game.  Deal with refreshing graphics.  Tracking coordinates.  Detecting and dealing with collisions.  Enemy AI...   Your program will naturally start to run fewer and fewer loops per second, as it's got more stuff to do per second.  At what point does your game now run at a FPS (limit) which is too slow to process every mouseinput that your OS generates?  What type of lag are you going to have to try to optimize out of your code elsewhere, just so you can process mousex/y positions that aren't really doing anything at all in your program?

If my program runs at a max 60 FPS, and the mouse reports 120 events per second, then it's going to take 2 seconds to process every second of mouse input!  

That's a seriously laggy game right there!
Reply


Messages In This Thread
while: wend - by fistfullofnails - 01-03-2023, 06:09 AM
RE: while: wend - by SMcNeill - 01-03-2023, 06:28 AM
RE: while: wend - by mnrvovrfc - 01-03-2023, 07:56 AM
RE: while: wend - by bplus - 01-03-2023, 03:39 PM
RE: while: wend - by mnrvovrfc - 01-03-2023, 07:54 PM
RE: while: wend - by bplus - 01-03-2023, 03:57 PM
RE: while: wend - by james2464 - 01-03-2023, 04:07 PM
RE: while: wend - by fistfullofnails - 01-05-2023, 07:36 AM
RE: while: wend - by SMcNeill - 01-05-2023, 08:38 AM
RE: while: wend - by Kernelpanic - 01-03-2023, 08:40 PM
RE: while: wend - by TempodiBasic - 01-04-2023, 12:13 AM
RE: while: wend - by bplus - 01-04-2023, 01:09 AM
RE: while: wend - by bplus - 01-04-2023, 01:55 AM
RE: while: wend - by SMcNeill - 01-04-2023, 02:52 AM
RE: while: wend - by bplus - 01-04-2023, 04:12 AM
RE: while: wend - by mnrvovrfc - 01-04-2023, 04:51 AM
RE: while: wend - by bplus - 01-04-2023, 05:22 PM
RE: while: wend - by Kernelpanic - 01-05-2023, 12:26 PM
RE: while: wend - by TerryRitchie - 01-05-2023, 04:55 PM
RE: while: wend - by TempodiBasic - 01-05-2023, 06:36 PM
RE: while: wend - by TerryRitchie - 01-05-2023, 11:04 PM
RE: while: wend - by fistfullofnails - 01-07-2023, 05:12 AM
RE: while: wend - by SMcNeill - 01-07-2023, 06:51 AM
RE: while: wend - by mnrvovrfc - 01-07-2023, 06:29 AM
RE: while: wend - by OldMoses - 01-07-2023, 01:55 PM



Users browsing this thread: 17 Guest(s)