-
Need some help
The program is doing something and I want to write something to it while it's working.
Example: I'm in a fight (DOS text-game) and I'm loosing. I want to run to an other room, but I can't do it because the command has no any effect while the fight goes on. When I get killed the command to go to an other room is executed and thats a bit too late. Anyone having some ideas how to fix this?
-
Get it to accept the command while you're in the fight.
-
I dont know how to do that. That's why I need help.
-
If I put a cin in the middle of fight code, the fight stops and that is not what I want. I want the fight to continue even when I'm writing and when I press enter, I want it to do the thing I wrote.
-
..."">>>""">>>">>"
how about (dunno if this works not tested)
Code:
while (!getch(key))
{
fight stuff
}
what u want it to do when u press 'key'
im not too good on key inputs so slap me if im wrong
-
Caze slaps -Xp-:p
It didn't work. Any more ideas?:confused:
-
you need to include conio.h, and replace 'key' with the key (may need quotes, etc (i dunno))
-
getch() doesn't take any parameters. It only works if I leave
getch() empty, and I have tried that and it didn't work.
-
try getche() with the e. it is a real function.
-
Umm, I'm not sure if it's standard but you can try using _kbhit() or kbhit() or something, it's a non-blocking function, meaning your game can get on with its life while you don't type anything.
Code:
while(theGameShouldBeRunning)
{
if(kbhit())
{
int char = getchar(); // or something along those lines; BTW, it won't wait for input,
// it'll just read whatever you hit to get kbhit() to set off.
if(char == 'q')
break; //q for QUIT
}
}
That's basically the idea, it might not be standard though, so if your compiler barfs then try rearranging the letters or just give up on it :p