Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

graveyard filla

HOW do i press any key to continue??????

This topic is 5380 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

high, i have a simple text RPG game and when the player kills someone, i want it to say "press any key to continue" and then execute then next line of code ive actually come up with this problem a lot and cant seem to fix it. the best way i came up with to do this is char holder; cout>>"Press any key then press enter to continue">>endl; cin << holder; but this forces the user to press a key THEN enter to continue the game. i also thought about using getline, considering it has a terminating argument IE when you press that key it will end therfore doing string holder; cout>>"Press enter twice to continue">>endl; getline (cin,holder,'/n') but that caused a whole load of problems throughout my whole game (i think it has something to do with cin.ignore() but i just would rather not mess with getline at all. anyway, so how do i do it? the problem is i have a bunch of clearscreens inside my game, so some stuff gets wiped out before you can see it, so my idea was to add a "press any key to continue" before i cleared the screen, so you could see what you were suposed to see. now that i think about it, isnt there a sleep() function that will wait an x amount of seconds before it goes to the next line of code? what is the sytax for that, and what headers to i include? maybe ill just make it delay instead, it seems to make more sence, although id still like an answer to my first question because i come up with that problem a lot. thanks for any help.... [edited by - graveyard filla on January 25, 2004 3:49:41 PM] [edited by - graveyard filla on January 25, 2004 3:50:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
use getch();

It reads in a single character from the command line and doesn''t display it.

Use getche() if you want the character to be displayed.

Share this post


Link to post
Share on other sites
And your other question about delaying, you can use Sleep(ms); let say if you want to delay 5 seconds you would use Sleep(5000); etc.

You might need to include windows.h for this btw.





--{You fight like a dairy farmer!}

Share this post


Link to post
Share on other sites
isn''t there a system call as well? One the even displays the "Press any key to continue..." line?

system("PAUSE");

don''t remember which include it needs but it''s bound to be one of these:
#include <iostream>
#include <conio.h>
#include <cstdlib>

Share this post


Link to post
Share on other sites
quote:
Original post by kVandaele
isn''t there a system call as well? One the even displays the "Press any key to continue..." line?

system("PAUSE");



That''s really really bad. What is does is start a second process, command or cmd, and execute one batch command, pause, then the command processor exits again. Because it has to be able to execute old dos programs it allocates 640K plus the whole dos interface.
System() is for the very lazy, a decent programmer should solve it the correct way.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!