Hello all, i am a new member of the GlBasic community and i want to request some help, with a curious problem i face.
I have some commands like
If key(11) = 1
.....
....
endif
and when i run the program, not only it doesn't recognize typing r, but also no button at all! In other programms, i face a stranger problem:
when i type something in the programm, i see other letters. For example, if i type "r", i see "q"... What can i do to fix it? The only thing i can input to my variables is numbers, but it's not enough for me...
I have search other problems with keyboard at the forum, but the other guy typed KEY(08) instead of KEY(8), so it's not satisfying for me
post a bit more code, please. I don't really understand your question.
KEY(i) - the "i" variable is a key code, not a character index.
SETSCREEN 640, 480, 1
LOADBMP "start.bmp"
PRINT "Would you like to take the red road or the yellow one?", 100, 320
PRINT "[R/Y]", 100, 340
IF KEY(19)= 1
CLEARSCREEN
LOADBMP "rpath.bmp"
ENDIF
That's it... When i say that i used a variable, i meant that the "user" would type red or yellow for himsel, but then i thought it would be simpler, just to give the choice between "r" or "y". When i tried that with a variable containing number, for example:
Input a, 100, 100
IF a=1
.....
ElSE a=2
....
ENDIF
That worked, but with the variable with characters or with hitting buttons, i cannot see any result. What i am trying to say, is that i am probably missing something about the keyboard when running a programm.
there's no loop in you program. KEY will not wait for a key input.
key(19) returns the state of the "R" key. 0= up, 1=down.
Could you write an example? I typed a While, but with what condition?
I mean that i typed a While True, but the programm didnt' responded and i had to shut it down.
Something like this.
SETSCREEN 640, 480, 1
LOADBMP "start.bmp"
LOCAL DONEQ%
WHILE DONEQ=0
PRINT "Would you like to take the red road or the yellow one?", 100, 320
PRINT "[R/Y]", 100, 340
IF KEY(19)
CLEARSCREEN
LOADBMP "rpath.bmp"
DONEQ=1
ELSEIF key(21)
CLEARSCREEN
LOADBMP "ypath.bmp"
DONEQ=1
ENDIF
SHOWSCREEN
WEND
Bit basic that example and not exactly streamlined or anything, but basically you need to keep showing the print because KEY doesn't wait around. You could always use BREAK to get out of the WHILE, but it's cleaner with a variable. Or you could make everything a single WHILE loop (I pretty much do for my latest game) and just use different handlers for different aspects of the game (SELECT CASE is a good command for example).
Cheers
Quote from: alzeus on 2012-Feb-10Input a, 100, 100
IF a=1
.....
ElSE a=2
....
ENDIF
If you want to allow the user to input text this should be:
Input a$, 100, 100
IF a$="r"
.....
ElSE a$="y"
....
ENDIF
But the way with a loop and KEY() is the better on.
You would need an ELSEIF (or a SELECT CASE or and ENDIF and another IF etc) on the a=2 otherwise you are setting a to 2.
Cheers
Alzeus - I ran into that problem when I first started. It's actually really simply. All programs that are constantly in motion work like this:
while true
<code>
showscreen
wend
If you don't have showscreen in there, the program will "hang." and display nothing!
Well, i can say that this problem is solved! Thanks guys for the immediate answer!