Help with WAITKEY()

BlitzPlus Forums/BlitzPlus Beginners Area/Help with WAITKEY()

Markh999(Posted 2005) [#1]
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


Damien Sturdy(Posted 2005) [#2]
umm,
"Flushkeys" before Waitkey? :)


Grey Alien(Posted 2005) [#3]
And after just to be safe. I always flush the keyboard buffer to avoid this sort of problem.


Markh999(Posted 2005) [#4]
Many thanks Mr Alien - that worked a treat.


WolRon(Posted 2005) [#5]
For another example of Tetris (in case you're curious) you could check out my programming tutorial.


Gauge(Posted 2005) [#6]
cancel that