Posts: 3,447
Threads: 376
Joined: Apr 2022
Reputation:
345
WHILE _MOUSEINPUT: WEND
While.... there's input in the mouse update buffer
Repeat
It basically clears and updates the mouse buffers so you're getting the current mouse status rather than some backlog of past X/Y positions which doesn't mean anything to you anymore.
Posts: 4,697
Threads: 222
Joined: Apr 2022
Reputation:
322
01-03-2023, 03:39 PM
(This post was last modified: 01-03-2023, 03:48 PM by bplus.)
"WHILE... WEND" was the only provided way by GW-BASIC to do loops without relying on "GOSUB/RETURN" and "GOTO".
Nope! For... Next was in there first even before While... Wend
Dartmouth BASIC - Wikipededia
Quote:List of BASIC statements
DEF
define single line functions
DIM
(short for dimension) define the size of arrays
END
define the end of the program
STOP
stop a program before the textual end
FOR / TO / STEP
define loops
NEXT
mark the end of loops
GOSUB
transfer control to simple subroutines
RETURN
return control from simple subroutines
GOTO
transfer control to another statement
IF / THEN
decision making
LET / =
assign formula results to a variable
PRINT
output results
DATA
store static data within the program
READ
input data stored in DATA statements
REM
comment ("REMark")
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 4,697
Threads: 222
Joined: Apr 2022
Reputation:
322
This use to be THE WAY to pause a program waiting for a key press.
Code: (Select All)
Print "We will pause until you press some key..."
While Len(InKey$) = 0: Wend
Print "Hello World!"
Now days there are better ways unless you want to blow the dust off your CPU fan.
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever
Posts: 229
Threads: 25
Joined: Aug 2022
Reputation:
23
"ELI5" attempt:
I was confused by this as well. WHILE _MOUSEINPUT: WEND looked like a single line of code to me. The : symbol is used to separate lines of code on the same line.
An example would be...
FOR t = 1 TO 10 : NEXT t
If you forget that and just think of it as two lines...
WHILE _MOUSEINPUT
WEND
Then you can just consider reply #2. But that was also confusing to me a while ago. I wondered how this doesn't just loop infinitely.
But it just goes and checks for the latest mouse input and then exits the loop.
Posts: 4,697
Threads: 222
Joined: Apr 2022
Reputation:
322
01-04-2023, 01:09 AM
(This post was last modified: 01-04-2023, 01:48 AM by bplus.)
Here's how to do _MouseInput without While...Wend but just a GOTO. A one liner like While _MouseInput :Wend and without double parking (2 statements separated with colon).
Code: (Select All)
_Title "Click to draw paths from one click to next" 'b+ 2023-01-03
Do
10 If Not _MouseInput Then GoTo 10
mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
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
EDIT: No sooner had I posted this when I realized the 2nd GOTO was not needed. Cool!
Looks like TempodiBasic was kinda close ;-))
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever