What is wrong with code?

BlitzPlus Forums/BlitzPlus Programming/What is wrong with code?

Jonman99(Posted 2005) [#1]
Print("press esc 5 times to quit!")
eschits=5
While(eschits)
If(KeyHit(1))
eschits=eschits-1
Print "Esc Hit"
Wend
If eschits=0
End

When I compile this and run the program. The first line is there along with a blank prompt for the second. Any idea why it doesnt work?


Grey Alien(Posted 2005) [#2]
this works perfectly, but yours doesn't!?

Graphics 640,480,16
Text(0, 0, "press esc 5 times to quit!")
Flip
eschits=5
y=20
LoopExit=0
FlushKeys
While eschits
		;escape key quits
		If (KeyHit (1)) Then
		Text (0,y, "Esc Hit")
		y=y+20
		eschits=eschits-1
		Flip
		EndIf
Wend
;If eschits=0
End



WolRon(Posted 2005) [#3]
By the way, your code should have been organized like this:
Print("press esc 5 times to quit!")
eschits=5
While(eschits)
	If KeyHit(1)
		eschits=eschits-1
		Print "Esc Hit"
	EndIf
Wend
End
(You were missing an EndIf, and the 'If eschits=0' line was unnecessary)

But I believe the reason it doesn't work, is because KeyHit and KeyDown are intended to be used in a 'graphical' app (meaning using the Graphics command).

So either use the Graphics command, or you will have to use something like Input, GetKey, or WaitKey.