Code causes lagg.
#1

Hello,
It's been a while ago since ive created this time-script, but today i really noticed that it gives some annoying lagg sometimes. I have set the timer to 2000 milliseconds. This is my code:

Код:
public Worldtime() {
	if(Minutes < 60) {
	    Minutes += 1;
	    SyncPlayerTime();
 	} else {
		if(Hours < 23) {
  			Hours += 1;
  			Minutes = 0;
  			SetWorldTime(Hours);
			SyncPlayerTime();
		} else {
	    	Hours = 0;
	    	Minutes = 0;
	    	SetWorldTime(Hours);
	    	SyncPlayerTime();
	    }
	}
}

public SyncPlayerTime() {
	for(new i=0; i<MAX_PLAYERS; i++) {
 		if(IsPlayerConnected(i)) {
 	  		SetPlayerTime(i,Hours,Minutes);
		}
	}
}
Does anyone see whats the laggy part, and how can i change it to minimalize/remove the lagg?

Greetz,
Danny
Reply
#2

And are you running Worldtime as a timer? If so, show me your SetTimer code.
Reply
#3

Eugh i cannot ready your code it's too busy, i'm sorry, please use correct identation next time:

Код:
public Worldtime()
{
    if(Minutes < 60)
    {
        Minutes += 1;
        SyncPlayerTime();
    }
    else
    {
        if(Hours < 23)
        {
            Hours += 1;
            Minutes = 0;
            SetWorldTime(Hours);
            SyncPlayerTime();
        } 
        else 
        {
            Hours = 0;
            Minutes = 0;
            SetWorldTime(Hours);
            SyncPlayerTime();
        }
    }
}

public SyncPlayerTime()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
            SetPlayerTime(i,Hours,Minutes);
    }
}
Can you check if the lags begins to show up every 60 seconds?
Reply
#4

@Mike:

Its underneath OnGameModeInIt:

Код:
SetTimer("Worldtime",MINUTE_INTERVAL,1);
The minute interval is 2000 millisecs aka 2 mins

@Relixious:
Sorry, i indentify my code on that way to reduce the file size (at least im trying to do that )
And the lagg is contant, it doesent show up every 2 mins.
Reply
#5

Bump, still not solved.
Reply
#6

the minute interval is 2000 millisecs aka 2 mins

2000 millisecs is 2 secs...
120000 is 2 mins

or do the define like 2*1000*60
Reply
#7

Quote:
Originally Posted by legodude
Посмотреть сообщение
the minute interval is 2000 millisecs aka 2 mins

2000 millisecs is 2 secs...
120000 is 2 mins

or do the define like 2*1000*60
I'd do it like this:

pawn Код:
#define MINUTE_INTERVAL 2
SetTimer("Worldtime",((MINUTE_INTERVAL*1000)*60),1); //2ms * 1000 = 2s | 2s * 60 = 2min
Reply
#8

Quote:
Originally Posted by -Danny-
Посмотреть сообщение
@Mike:

Its underneath OnGameModeInIt:

Код:
SetTimer("Worldtime",MINUTE_INTERVAL,1);
The minute interval is 2000 millisecs aka 2 mins

@Relixious:
Sorry, i indentify my code on that way to reduce the file size (at least im trying to do that )
And the lagg is contant, it doesent show up every 2 mins.
Reducing the size of your .pwn does not reduce the size of your .amx - unless of course we're talking more efficient code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)