BDIALOG - Show a dialog box and wait for a button press.
But that function already exists!
It does, but it's terrible. The return values hardly make sense and you can only specify certain
sets of buttons you want to accept (and the format is annoying too.) I figured I'd try to tame this function a bit.
pressed% = BDIALOG(message$, buttons%, title$, time%)
message$ ' Dialog box body text.
buttons% ' Buttons you want to accept.
caption$ ' Dialog box title.
time% ' Time (seconds) until dialog closes (0 or FALSE to disable.)
pressed% ' The button pressed by the user, or 0 if timed-out.
Some examples to help demonstrate the purpose of this function:
PRESS%=BDIALOG("PRESS A QUICKLY!",#A,"HURRY HURRY",1)
CHOICE%=BDIALOG("A for Game A, B for Game B?",#A OR #B,"Mode Select",FALSE)
Note that this is a user
DEF so there are no optional arguments like the built-in
DIALOG forms; you have to specify every value.
Function Code
DEF BDIALOG(TEXT$,BTN%,TITLE$,TIME%)
VAR BIT%,RES%
'prepare button type bitmask
IF BTN% AND &B0011110000 THEN INC BIT%,1
IF BTN% AND &B0000001111 THEN INC BIT%,2
IF BTN% AND &B1100000000 THEN INC BIT%,4
BIT%=-BIT%
IF !BIT% THEN RETURN 0 'exit if no valid choices
REPEAT
RES%=DIALOG(TEXT$,BIT%,TITLE$,TIME%)
IF !RES% THEN
'timed out
RETURN 0
ELSE
'convert output into the
'corresponding button bit
RES%=1<<RES%-128
IF RES% AND &B00001111 THEN
RES%=RES%<<4
ELSEIF RES% AND &B11110000 THEN
RES%=RES%>>4
ENDIF
'return if the button pressed is acceptable
RES%=RES% AND BTN%
IF RES% THEN RETURN RES%
ENDIF
UNTIL FALSE 'forever/until we RETURN from this function
END
This function could be especially useful if wired up to a dialog menu builder or something like that. Just a building block for something more interesting.
Note that you will get dialog flicker on some wrong/unaccepted presses. That's because the DIALOG built-in it's based on is bad.