10-01-2022, 01:07 PM
Here are two examples that do the same thing, but have different coding formats...
Pete
Code: (Select All)
LINE INPUT "Input 1 for simple or 2 for complex demo: "; ans$
IF ans$ = "" THEN END
IF ans$ = "1" OR ans$ = "2" THEN ELSE BEEP: CLS: RUN
CLS
PRINT "Press any 2-combo of cursor arrow keys...": PRINT
IF ans$ = "1" THEN
DO
_LIMIT 30
IF _KEYHIT < 1 THEN
IF _KEYDOWN(18432) AND _KEYDOWN(19200) THEN
IF flag = 0 THEN PRINT "a & b": flag = -1
ELSEIF _KEYDOWN(18432) AND _KEYDOWN(19712) THEN
IF flag = 0 THEN PRINT "a & c": flag = -1
ELSEIF _KEYDOWN(18432) AND _KEYDOWN(20480) THEN
IF flag = 0 THEN PRINT "a & d": flag = -1
ELSEIF _KEYDOWN(19200) AND _KEYDOWN(19712) THEN
IF flag = 0 THEN PRINT "b & c": flag = -1
ELSEIF _KEYDOWN(19200) AND _KEYDOWN(20480) THEN
IF flag = 0 THEN PRINT "b & d": flag = -1
ELSEIF _KEYDOWN(19712) AND _KEYDOWN(20480) THEN
IF flag = 0 THEN PRINT "c & d": flag = -1
END IF
END IF
IF flag THEN
a = _KEYDOWN(18432) + _KEYDOWN(19200) + _KEYDOWN(19712) + _KEYDOWN(20480)
IF a = 0 THEN flag = 0: CLS
END IF
LOOP
ELSE ' Demo 2.
REDIM flag(4)
DO
LOCATE 3, 1: PRINT "ky ="; ky
_LIMIT 30
IF flag2 = 0 THEN
IF _KEYDOWN(18432) AND flag(1) = 0 THEN ky = ky + 1: flag(1) = -1
IF _KEYDOWN(19200) AND flag(2) = 0 THEN ky = ky + 2: flag(2) = -1
IF _KEYDOWN(19712) AND flag(3) = 0 THEN ky = ky + 4: flag(3) = -1
IF _KEYDOWN(20480) AND flag(4) = 0 THEN ky = ky + 8: flag(4) = -1
END IF
IF ky THEN
SELECT CASE ky
CASE 3
IF flag2 = 0 THEN
PRINT "a & b"
flag2 = -1
ELSE
GOSUB flag_check
END IF
CASE 5
IF flag2 = 0 THEN
PRINT "a & c"
flag2 = -1
ELSE
GOSUB flag_check
END IF
CASE 6
IF flag2 = 0 THEN
PRINT "b & c"
flag2 = -1
ELSE
GOSUB flag_check
END IF
CASE 9
IF flag2 = 0 THEN
PRINT "a & d"
flag2 = -1
ELSE
GOSUB flag_check
END IF
CASE 10
IF flag2 = 0 THEN
PRINT "b & d"
flag2 = -1
ELSE
GOSUB flag_check
END IF
CASE 12
IF flag2 = 0 THEN
PRINT "c & d"
pete = 1
flag2 = -1
ELSE
GOSUB flag_check
END IF
CASE ELSE
GOSUB flag_off
END SELECT
_KEYCLEAR
END IF
LOOP
END IF ' Demo loop.
flag_check:
a = _KEYDOWN(18432) + _KEYDOWN(19200) + _KEYDOWN(19712) + _KEYDOWN(20480)
IF a = 0 THEN GOSUB flag_off
RETURN
flag_off:
ky = 0: REDIM flag(4): flag2 = 0: CLS
RETURN
Pete