Hi,
sorry for the bad topic name, I don't really have a better idea for now.
So llet's imagine I have a timer:
timer questtimer;
and then a while loop:
while(true) {
if(questtimer.elapsed%60000== 0) { //just as example, we check if the number is a full minute, if yes, we do something
whatever, some code
}
wait(5); //here's the reason why I am asking for help.
I need to call wait(5) to avoid weird behaviour and not responding windows, but that also means my timer will get out of sync, and eventually, this if statement above will just not trigger ever. How would I manage countdowns or timers for such a case, in my case a timer for a mini game, in which you only have limited time, and it should announce the left time every full minute?
Sorry if this was kinda weird explaned or written, I hope you understand what I mean and maybe have a solucion. thanks.
If the while loop would go on every 5 miliseconds, the 12,000th loop would land on exactly 60,000 milliseconds. Yes, the loop could be delayed for a few ms but there isn't anything else you could do I believe. There might be, but I'm not sure wether it's worth maximally 1-5 ms.
I have a quesstion. Why don't you use t.elapsed < 60000
condition? It will make it simple and it will do the same.
I don't quite understand the question. wait(5) waits for 5 milliseconds at the very end of your loop, but that shouldn't be enough to make your timers be off. To be fair though I've never tried calling opMod (%) on a timer's elapsed value before, and that would probably require millisecond-level precision. The way I'd do this is something like:
timer announcer;
const int ANNOUNCE_TIME = 60000; // In MS
while (true) {
if (announcer.elapsed >= ANNOUNCE_TIME) {
announcer.restart();
// ...
}
wait(5);
}
The timer class also has a .has_elapsed(int time_to_check) function, but I found that using it in certain places in my game caused elapsed checks to not work properly for some super weird reason, so I always just do it how I showed above.