Time - Hour and minute
#1

Will anyone help me fix the error?
The hour is showing up 15:08, 15:09, 15:, 15:11.
"15:10" did not show up. only "15:"

Код:
new Minute;                            
new Hour;                                      

public OnGameModeInit() 
{
    Minute= 0;
    Hour= 5;
    SetTimer("TimeU",100,true);
    return 1; 
} 

forward TimeU();
public TimeU()
{
    new string[7];                             
    Minute+=1;                                      
    if(Minute==60) {                                
        Minute=00;
        Hour+=1;                                  
    }
    if(Hour==24) {
        Minute=00;
        Hour=0;
    }
    if(Minute<10) {                                 
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
    if(Minute>10) {
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
    if(Hour<10) {
                                                  
        format(string,sizeof(string),"0%d:%02d",Hour,Minute);
    }
    for(new i; i<MAX_PLAYERS; i++) {              
        if(IsPlayerConnected(i)) {              
            SetPlayerTime(i,Hour,Minute);           
        }
    }
    TextDrawSetString(TimeTD,string);
    return 1;
}
Reply
#2

Код:
if(Minute<10) {                                 
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
    if(Minute>10) {
                                                  
        format(string,sizeof(string),"%d:%02d",Hour,Minute);
    }
You are first checking if minute is smaller than ten, then checking if it is greater than ten. Ten however is exactly ten, so it will not be considered (it isn't greater nor lower).

So you will need to include ten into the later check (change it to "Minute >= 10").

Or just use:

Код:
format(string,sizeof(string),"%02d:%02d",Hour,Minute);
Reply
#3

Also its 1000, not 100
pawn Код:
SetTimer("TimeU",1000,true);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)