Computer Science Canada Time counting down simultaneously |
Author: | MysticVegeta [ Tue May 24, 2005 4:29 pm ] |
Post subject: | Time counting down simultaneously |
Hi, There is a section in my program that asks for user input but at the same time, the seconds decrease. How can i make both of them work at the same time without using processes. Processes screw the user input location so bad... |
Author: | Cervantes [ Tue May 24, 2005 4:51 pm ] | ||||
Post subject: | |||||
That depends on how you're getting the input. If you're using get, well, let's not go there. If you're using getch(), that's a little better, because at least you could update your timer in the time between the user's keystrokes! However, the best way to do this is wrap your getch() statement inside an if hasch statement. Thus, the getch() code is only executed if there is a key waiting in the buffer.
Expanding this to include adding the getch() to a variable and adding a timer, we get something like this:
|
Author: | MysticVegeta [ Tue May 24, 2005 4:58 pm ] |
Post subject: | |
How about if i using get |
Author: | Cervantes [ Tue May 24, 2005 5:33 pm ] |
Post subject: | |
I don't think you can. You will, most definately, have to switch to the getch/hasch combo. |
Author: | MysticVegeta [ Tue May 24, 2005 5:42 pm ] |
Post subject: | |
But its a whole word... processes... |
Author: | Cervantes [ Tue May 24, 2005 5:58 pm ] |
Post subject: | |
MysticVegeta wrote: But its a whole word...
Yes, but a word is composed of letters. If you think of how exactly you type a word out on the keyboard, you press one key at a time in a specific order so you produce a word. To model that, we need to getch() one key at a time in the order that they come to produce a specific word. Sure, get is meant for things like this, but that doesn't mean it's the way to go. Look at Hitler: he meant to take over Europe (and more!) but he failed. He failed, just like get will fail you with this. Oh, the analogies. Hitler is a programming command? omgwtfbbq. |
Author: | MysticVegeta [ Wed May 25, 2005 3:20 pm ] |
Post subject: | |
hmm i think i know what you mean, i will try to do something like that. |