I think I've did a fairly decent job explaining about WHY the mousewheel behaves the way it does above, but here's one last demo to illustrate the behavior for us, and to highlight HOW we can move checking it outside out WHILE:WEND loop as well:
Now, Why does this work? Let me steal from my example above, so I can supply an explaination:
We’re reading from a buffer a few nanoseconds long.
We read the buffer with the mouse in the top left corner: X = 0, Y = 0, Wheel = 0
3 nanoseconds later, we read the buffer again:
BUFFER START
0.5 Nanoseconds: Mouse X = 1
1.0 Nanoseconds: Y = 1
1.5 Nanoseconds: X = 2, Y = 2
2.0 Nanoseconds: Wheel = +1 (scrolled up)
2.5 Nanoseconds: Wheel = 0 (back to normal, after it “clicked”)
3.0 Nanoseconds: X = 3
BUFFER STOP
Basicallly, the WHILE conditions we set for our main loop are WHILE THERE'S MOUSE INPUT AND NO WHEEL ACTIVITY, CLEAR THE BUFFER. ( WHILE _MOUSEINPUT <> 0 AND _MOUSEWHEEL = 0: WEND)
So we end up reading only a small portion of our buffer:
0.5 Nanoseconds: Mouse X = 1
1.0 Nanoseconds: Y = 1
1.5 Nanoseconds: X = 2, Y = 2
2.0 Nanoseconds: Wheel = +1 (scrolled up) <--- AT THIS POINT, WE EXIT THE BUFFER!
The rest of our information stays buffered, waiting for the next pass to process, but if we go ahead and run our program at this point, X = 2, Y = 2, and the wheel = +1. (The truth is, our mouse is actually at X =3 currently -- we just haven't read our buffer fully yet -- but it was at X/Y point 2, 2 when the scrolling occurred.)
On the next loop of our program, as soon as we start reading from the mouse buffer again, the next 2 events will be:
BUFFER START
0.5 Nanoseconds: Wheel = 0 (back to normal, after it “clicked”)
1.0 Nanoseconds: X = 3
BUFFER CONTINUES...
Reading the mouse wheel doesn't have to be inside your update loop, as proven here, but it's generally the easiest way for folks to deal with it and just forget about it.
Which seems simpler?
Or:
It's really just an instance of coding style, as both work perfectly fine the way they are. The important thing is knowing
WHY they both work for us, though that can't be quite as important as simply knowing
HOW to make it work properly. Even if the concept behind the two methods is something you forget in the future, at least remember the syntax so you can utilize one or the other of them, so you can have access to mouse wheel information in your programs.