• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Countdown timer.. Is this a good way to go about it?

K

Kamon145

Guest
Hi everyone, this is less of a programming issue and more of a "does the way Im doing this seem efficient and make sense" kind of question. Hope this is still the proper forum for it, anyways I have a countdown timer in my game and I want it to stay very accurate even at long times and times where game rate may slow. I am using the current time to do this in the following manner
Code:
//Create Event :
cur_sec = current_second;
global.minutes = 2;
global.seconds = 60;
timer_start = false;

//Step Event
//This line is just for testing to start the timer right at the beginning of a minute
if current_second == 0 && timer_on == false
timer_on = true
if timer_on = true
{
    if current_second > cur_sec
    {
        cur_sec = current_second;
        global.seconds -= 1;
    }
    else
    if current_second == 0 && cur_sec != 0
    {
        cur_sec = 0
        global.seconds = 59;
        global.minutes -=1;
    }
}
This seems to work well, however I've only used it in a small test project so far so I'm not sure how it will act in the long run.. Does anyone see any potential bugs in doing things this way? if the game lags just right is everything gonna get thrown off?
 

obscene

Member
Seems a very complicated way, when instead you could just do it in one variable, one line...

timer-=1/room_speed;

And then just draw your seconds with timer mod 60 and your minutes with timer div 60.

If your game does end up running slow, the timer will slow too, but that's probably the fairest way to do it.
 
K

Kamon145

Guest
Seems a very complicated way, when instead you could just do it in one variable, one line...

timer-=1/room_speed;

And then just draw your seconds with timer mod 60 and your minutes with timer div 60.

If your game does end up running slow, the timer will slow too, but that's probably the fairest way to do it.
thank you for the reply, I did something simalar to that at first but when I drew the actual time using current_seconds/current_minutes it seemed my timer became misaligned after about 2 minutes and progressively got worse, not sure what wad causing it but somebody told me with this method I lose 1 10th of a second each second, not sure if that’s accurate or not but it definitely became misaligned after a while. I will try it again when I get home side by side and see if it was just a fluke or an error on my part
 
Top