Countdown of the gametime. Minutes and seconds
#1

I'm trying to create a function to note the time left, until the game ends, but it fails. The calculation to calculate the seconds works perfectly, but if the seconds are above 60, it will fail. Same for the minutes.

This is the code I am using to countdown.
A timer has been set every second on this 'callback'.
pawn Код:
public Timer()
{
    new time[6];
    Seconds--;
    Minute = Seconds/60;
    format(time, 6, "%d:%d",Minute, Seconds);
    if(Seconds == 0) return Seconds = 60;
    TextDrawSetString(TDraw, time);
    return 1;
}
And I'm using this to start the timer.
pawn Код:
Seconds = ((30000+time)/1000);
    SetTimer("Timer", 1000, true);
It's actually really easy to calculate this. But it's hard to calculate this for a script.

Thanks
Reply
#2

if(Seconds > 0)
{
Seconds--;
}
Reply
#3

Do you even understand my problem? What you're posting there isn't related to my problem at all.
Reply
#4

like this?
pawn Код:
new seconds = 1508;

new minutes,tempsec;
    tempsec = seconds;
    while(tempsec > 60){
        minutes++;
        tempsec = tempsec - 60;
    }
printf("%d:%d",minutes,tempsec);
Reply
#5

Ah, I got it working now.
I used if before, instead of while.

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)