Global time bug
#1

This is my global time system:
PHP код:
public TimeU()
{
    new 
string[7];
    
Tsec+=1;
    if(
Tsec==60)
    {
        
Tsec=00;
        
THrs+=1;
    }
    if(
THrs==24)
    {
        
Tsec=00;
        
THrs=0;
    }
    if(
Tsec<10)
    {
        
format(string,sizeof(string),"%d:0%d",THrs,Tsec);
    }
    if(
Tsec>10)
    {
        
format(string,sizeof(string),"%d:%d",THrs,Tsec);
    }
    if(
THrs<10)
    {
        
format(string,sizeof(string),"0%d:%d",THrs,Tsec);
    }
    for(new 
ii<MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i))
        {
            
SetPlayerTime(i,THrs,Tsec);
        }
    }
    
TextDrawSetString(Time,string);

But there is a problem
For example, when time is 2:2, it is is showing 02:2 instead of 02:02

How can I fix it?
Reply
#2

Simple enough. No need to check for seconds, etc.

pawn Код:
format(string, sizeof(string), "%02d:%02d", THrs, Tsec);
Reply
#3

Found out the problem.

Why it always happens. Everytime, I tries to fix the problem my self and I won't find any solution. And then, Ill post here.

But, as soon as I post here, I'll find out the solution myself. -_-

EDIT:
Quote:
Originally Posted by ]Rafaellos[
Посмотреть сообщение
Simple enough. No need to check for seconds, etc.

pawn Код:
format(string, sizeof(string), "%02d:%02d", THrs, Tsec);
Sorry, I didn't see your post. I fixed it myself. The problem was in the 5th 'if', that if changes everything in the string. Anyway, thanks for your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)