Timer in the game

I am begginer.. and I have some kind of trouble with making my game. I don't know how to count time while "person is thinking" from one pressed enter to next.. Help

You would need to create a separate thread for the timer - not ideal for a beginner.
Actually if all you want to do is time how long it takes for the user to input something, you can get the time before and wait for the input. After the input is received, get the time again. Subtract the first time from the second time and the difference is how much time was taken. Use http://www.cplusplus.com/reference/ctime/ctime/?kw=ctime
I think @Softrix thought you wanted to have a runtime during said game. He was right when he said to use threading, and threading is much too difficult for beginners, but there is a very crude and archaic way to do so without threading.

Have a loop that runs for a certain amount of time. This can work by using getting the time at the beginning and ruinning as long as the new time you keep on reading is not greater than the original plus an integer value;

Pseudo-code:

while(true)
{

origtime = Time(0);

do
{

//any user input

newtime = Time(0);

}while(newtime < (origtime+5));

//Update screen

}

This means for a certain amount of time the user can input, then when the loop is broken, everything the user pressed is updated. Then it is thrown back into the loop again for more user input.

THIS IS A VERY BAD WAY TO MAKE A GAME. I don't actually condone this, but it works...
Last edited on
Topic archived. No new replies allowed.