Adding a Timer

Doing the TripleX code for training, i got the idea of Adding a TImer when the player gets the wrong Answer, but when i try do make it run on the background, it still makes it that blocks all Players Input, so he Can’t try again. Any ideas?

What you’re doing here is touching on multi-threaded applications and it’s quite complex. When you use Sleep this pauses the application for the specified duration.

Try using this instead:
std::this_thread::sleep_for(1000ms);

I am not 100% sure this will solve your issue but give it a try.

No it doesn’t work, i think is because that thread that summons the timer to start is the same one that helps progressing the loop for the player to try again, so wont it be stopping all capacity for the player to continue?

In that case, you want to use std::thread to create a new thread and start it.
It’s fairly easy to use.

std::thread timerThread(timer);

Will start a the thread and if you need to wait for it to finish at any point, add

timerThread.join();

A link to the reference docs are here which should help you. Note that threaded output to the console will be quite strange and may output text in the middle of any user input.

thread - C++ Reference (cplusplus.com)

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms