Home
Products
Community
Manuals
Contact
Login or Signup

Help with WAITKEY()

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

Markh999(Posted 1+ years ago) #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 1+ years ago) #2
umm,
"Flushkeys" before Waitkey? :)


Grey Alien(Posted 1+ years ago) #3
And after just to be safe. I always flush the keyboard buffer to avoid this sort of problem.


Markh999(Posted 1+ years ago) #4
Many thanks Mr Alien - that worked a treat.


WolRon(Posted 1+ years ago) #5
For another example of Tetris (in case you're curious) you could check out my programming tutorial.


Gauge(Posted 1+ years ago) #6
cancel that