Reading inputs
Author |
Message |
BenLi
|
Posted: Wed Jun 14, 2006 8:17 pm Post subject: Reading inputs |
|
|
I myself have always used Input.KeyDown for getting keyboard input. What do the other ones do and how can they be advantageous
eg. hasch, getch |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheOneTrueGod
|
Posted: Wed Jun 14, 2006 8:32 pm Post subject: (No subject) |
|
|
getch (or getchar) will cause the program to interrupt, and wait for user input. It will only accept one character, and will cause the blinky (For lack of a better word) bar to appear in the top left corner.
Theres ways to avoid both of the problems. hasch is a function that returns true if there is input waiting to be collected from the keyboard buffer (I.E. if the user has pressed a key) When used in conjunction with getch, i.e.
code: | if hasch then
getch(ch)
end if |
It makes it so the program doesn't interrupt while waiting for input. To get rid of the 'blinky bar', use View.Set plus the correct parameter (forgot what it was)
However, there are still problems with the getch method. Ever noticed how, in old games, when you hold the key down for upwards of 3 seconds, and then you let go of the key, your character still moves for a bit? Thats because the keyboard buffer holds more than one key at once, but you're only reading in one per loop. The only way to get rid of this is to flush the keyboard buffer (I don't know how to do this, might be Input.Flush or some'n like that, search around.)
Also, if you hold the key down, the character will kinda move in a jumpy fashion. Theres probably ways around this as well, but I havn't experimented to the point where I could tell you how.
In summary, its probably better to use Input.KeyDown because it does a lot of the work for you...
Anyone who knows more than me want to add anything? |
|
|
|
|
|
Clayton
|
Posted: Wed Jun 14, 2006 8:35 pm Post subject: (No subject) |
|
|
hasch doesnt return what key was pressed so... ya, getch pauses the program to get a one character input so... ya, however if you absolutely want to use getch in a game where you just need to check if a key has been pressed then use a combo of hasch and getch ex.
code: |
if hasch then
getch (a)
end if
|
this works because hasch returns a boolean value, and if a button is pressed then getch will read the button pressed, however, i would stick to Input.KeyDown |
|
|
|
|
|
Bored
|
Posted: Wed Jun 14, 2006 8:51 pm Post subject: (No subject) |
|
|
Well you see it's all a matter of need. The getch() funtion is used in situations when you would like to recieve one character, such as making your own get command to work with fonts. Meanwhile if you would like to run other parts of the program while waiting for input then you can add in hasch(), such as say you are waiting for a user to continue with y or n and would like to have a cool background playling all the while. Then Input.Keydown is used when you need to get multiple keys simulataniously and know which keys to look for such as player controls. there are also a few other commands that are helpfull such as Input.Pause which waits till the user presses a key, then continues. This is good for those press any key moments and is the rough eqivilent of
code: | loop
exit when hasch
end loop |
Well just remmebr that it's not a matter of this is better then this, but a matter of this is more sooted for this situation then this, meanwhile this is more suted for this situation. |
|
|
|
|
|
Clayton
|
Posted: Wed Jun 14, 2006 9:07 pm Post subject: (No subject) |
|
|
arrrrgh TOTG u beat me to it didnt catch ur post but anyways, the View.Set command u are looking for is "nocursor", and
TheOneTrueGod wrote:
and will cause the blinky (For lack of a better word) bar to appear in the top left corner
omg u didnt, "little blinky thing" lol its called a cursor |
|
|
|
|
|
TheOneTrueGod
|
Posted: Wed Jun 14, 2006 10:05 pm Post subject: (No subject) |
|
|
lol superfreak, its exam time.. brain hurty... anyways, like bored said, there is no "truly" better method, it all depends on circumstance. You can make some pretty sexy looking input using Font.Draw, string concatenation, and getch. |
|
|
|
|
|
Clayton
|
Posted: Wed Jun 14, 2006 10:08 pm Post subject: (No subject) |
|
|
lol i know what u mean i have 4 exams next week and revising is a b***h, but yea, i know a kid in my school came up with a very "sexy" (in your words) looking input module that basically turned input into font and did all sorts of cool stuff as well |
|
|
|
|
|
|
|