Help with WAITKEY()
BlitzPlus Forums/BlitzPlus Beginners Area/Help with WAITKEY()
| ||
I’m writing a Tetris game which is fine except when moving between levels. Below is the main routine and the new level function. When the level ends the Gnewblock$ gets set to “Y” (in another function not shown). This should mean that Function Finitnewlevel gets called from the main program, display the line “Press any key to start” and then WAIT for player to press something. Problem is it seems to execute Finitnewlevel ok (because the message flashes on the screen) but then it goes straight into the new level without waiting for a key to be pressed. Any ideas? ;================== ;MAIN PROGRAM LOOP ;================== While Not KeyHit(Gescapekey) Finitnewlevel() While (Gnewlevel$="N") Fmoveleftright() Fcontrolblockmovement() Fprintgrid() Flip Delay 200 Wend Wend End ;========================= ;INITIALISE FOR NEW LEVEL ;========================= Function Finitnewlevel() For Lcnt=1 To (Gheight+4)*Gwidth:Agrid(Lcnt)=0:Next Gtime=MilliSecs() Fprintgrid() Text 320,450,"Press any key to start" Gnewlevel$="N":Gnewblock$="Y" Flip WaitKey() End Function |
| ||
umm, "Flushkeys" before Waitkey? :) |
| ||
And after just to be safe. I always flush the keyboard buffer to avoid this sort of problem. |
| ||
Many thanks Mr Alien - that worked a treat. |
| ||
For another example of Tetris (in case you're curious) you could check out my programming tutorial. |
| ||
cancel that |