Posts: 285
Threads: 70
Joined: Feb 2005
If you have tried any of my patterns programs I posted, and those involving playing MOD/MID files you may have noticed the INKEY$ functions sometimes only allows you to abort the program during the first few seconds or so.
So there must be a bug in FB, because the patterns all abort with QB at anytime. Has anyone found a solution to the problem?
Gordon
Posts: 1,407
Threads: 117
Joined: Dec 2002
Perhaps the problem is in the way you exit the GOSUB when the key is pressed.
Code: IF INKEY$ <> "" THEN GOTO done
You must ALWAYS exit a GOSUB with RETURN. Otherwise you are corrupting the stack. Anything can malfunction if you do that...
Then, if you don't save the pressing of the key in a flag, the user will have to press the key a second time to exit the main loop and another one to end the SLEEP at the end of the program.
I hope it helps.
Antoni
Posts: 285
Threads: 70
Joined: Feb 2005
Thanks for your advice Antoni, but no luck. As you can see I have now made sure to close the remaining For Next and While Wend loops when aborting. But if you compile this program with FB and run it, you have only about 20 seconds to press the space bar or it is back to the dreaded Al+Ctrl+del to terminate.
There is no such probem if compiled with QuickBasic
Gordon
Code: DEFSNG A-Z
REM KALIEDSCOPE originaly Written for the UK BBC Electron
DIM X(3, 3), Y(3, 3), XC%(7), YC%(7)
SCREEN 12: LOCATE 10, 20
PRINT "Press Spacebar anytime to Quit" : sleep 2000
RANDOMIZE TIMER: start = TIMER:RESTORE 500
FOR I% = 1 TO 7
READ XC%(I%), YC%(I%)
NEXT
SCALE1 = 250: SCALE2 = 400: WINDOW
FIN = 0: C = 1: C% = 0
WHILE FIN = 0: CLS
S$ = "A"
FOR P = 1 TO 2: CLS
IF P = 2 THEN S$ = "B"
C = C + 1: IF C = 4 THEN C = 1
FOR L% = 1 TO 6
GOSUB 300: REM CALCS
PC% = INT(RND * 15) + 1: COLOR PC%
IF S$ = "A" THEN K% = 1: GOTO 140
FOR K% = 1 TO 7
140 WINDOW (0 - XC%(K%), 0 - YC%(K%))-(1279 - XC%(K%), 1023 - YC%(K%))
GOSUB 410: REM TRIANGLES
IF S$ = "A" THEN GOTO 180
NEXT K%
180 NEXT L%
REM Attempts to avoid full screen color flood
ST = -600: EN = 600: IF S$ = "B" THEN ST = -50: EN = 1150
CX% = 0: SX% = 0
FOR TX% = ST TO EN STEP 20
SX% = SX% + POINT(TX%, 0)
CX% = CX% + 1
NEXT TX%: TX% = TX% - 20
IF SX% MOD CX% = 0 THEN GOTO 190
REM Check for Abort
locate 1,4: print int(TIMER-start)
sleep 2000 : IF INKEY$ = " " then P = 9 : FIN = 1
190 NEXT P
WEND : end
300 REM CALCS
IF S$ = "A" THEN SCALE = SCALE2 ELSE SCALE = SCALE1
FOR J% = 1 TO 3
R = SCALE * RND: TH = 1.047 * (RND + .5)
X(1, J%) = R * COS(TH): Y(1, J%) = R * SIN(TH)
XH = X(1, J%) / 2: XV = X(1, J%) * .866
YH = Y(1, J%) * .866: YV = Y(1, J%) / 2
X(2, J%) = YH + XH: Y(2, J%) = -YV + XV
X(3, J%) = YH - XH: Y(3, J%) = -YV - XV
NEXT J%
RETURN
410 REM TRIANGLES
FOR I% = 1 TO 3
PSET (X(I%, 1), Y(I%, 1))
LINE -(X(I%, 2), Y(I%, 2))
LINE -(X(I%, 3), Y(I%, 3)): LINE -(X(I%, 1), Y(I%, 1))
PX% = (X(I%, 1) + X(I%, 2) + X(I%, 3)) / 3
PY% = (Y(I%, 1) + Y(I%, 2) + Y(I%, 3)) / 3
PAINT (PX%, PY%)
PSET (-X(I%, 1), Y(I%, 1))
LINE -(-X(I%, 2), Y(I%, 2))
LINE -(-X(I%, 3), Y(I%, 3)): LINE -(-X(I%, 1), Y(I%, 1))
PX = (-X(I%, 1) + -X(I%, 2) + -X(I%, 3)) / 3
PY = (Y(I%, 1) + Y(I%, 2) + Y(I%, 3)) / 3: PAINT (PX, PY)
NEXT I%
RETURN
500 DATA 640,514,370,994,910,994,1180,514,910,34,370,34,100,514
Posts: 1,407
Threads: 117
Joined: Dec 2002
Gordon:
I think you are right, it does'nt react to INKEY$
The program seems to not read keys with INKEY$.
I changed your key test to IF LEN(INKEY$) THEN , it should react to ANY key, and it reacts only to a mouse click to the close button (that translates to the keys chr$(255)+"X") and gives an error when closing
However if I change the condition to IF MULTIKEY(1) THEN (reacting to the escape key) the program works correctly.
Lillo?
Antoni
Posts: 285
Threads: 70
Joined: Feb 2005
Thanks again Antoni,
You have cracked the problem, but I can find no mention of MULTIKEY in either the QB, QuickBasic or the FB keywords.txt. I have had to put a note to hold the Esc key down until accepted.
One final bug in the KALIEDSCOPE Mod/Mid player is the list of files fails to show after a few re-starts.
Gordon
Posts: 336
Threads: 4
Joined: Nov 2004
Multikey is listed in lillo gfx txt file should be with the lastest package of FB
|