Blitz3D+ Command Reference

MouseWait ( )

Parameters

None.

Description

Halts the program until a mouse button is clicked, then returns which one.

MouseWait and WaitMouse are the same command: both names call exactly the same routine in the runtime, and either spelling is fine in your code. WaitMouse is the one that matches WaitKey and WaitJoy, so new code usually uses that.

It returns the button number - 1 left, 2 right, 3 middle - which makes it a one-line way to offer a choice on a pause or title screen.

The gotcha is the blocking. While it waits, your loop is stopped: nothing animates and anything drawn to the back buffer is still invisible, so draw the screen and Flip it before you call. A click that was already queued satisfies the wait straight away, so use FlushMouse first when you want a genuinely fresh click. During normal gameplay reach for MouseHit in your main loop instead.

See also: WaitMouse, MouseHit, GetMouse, FlushMouse, WaitKey.

Example

; MouseWait Example
; -----------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; Draw the title frame FIRST, then halt - the player needs to see
; the prompt while the program is blocked inside MouseWait.
Cls
Text 320,180,"*  S H O O T I N G   R A N G E  *",True
Text 320,220,"Click any mouse button to start",True
Flip

; MouseWait halts the program until a mouse button is pressed and
; returns its code (1=left, 2=right, 3=middle).
button=MouseWait()

While Not KeyDown(1)

    Cls

    ; A live crosshair so the range feels alive after the title
    Color 255,255,0
    Oval MouseX()-10,MouseY()-10,20,20,False
    Line MouseX()-14,MouseY(),MouseX()+14,MouseY()
    Line MouseX(),MouseY()-14,MouseX(),MouseY()+14

    Color 255,255,255
    Text 0,0,"Esc: exit"
    Text 0,20,"MouseWait() returned button "+button+" on the title screen"
    Text 0,40,"(1=left, 2=right, 3=middle)"

    Flip

Wend

End

Index