define outside of a repeating code part?
#1

hi,

lets take a look at this code:

pawn Код:
forward Timer1Sec();
public Timer1Sec()
{
        new rhour,rminute,rsecond;
        gettime(rhour,rminute,rsecond);
        new stringt[22],stringts[10];
        format(stringt,sizeof stringt,"~y~%d~w~:~y~%d",rhour,rminute);
        TextDrawSetString(RealTime,stringt);
        format(stringts,sizeof stringts,"~w~%d",rsecond);
        TextDrawSetString(RealTimeS,stringts);
        return 1;
}
This is a code to show and update a clock textdraw displaying the real time to all players.
It runs in a timer with an interval of 1 second so the textdraw (that is showing also seconds in the clock) runs smooth.
Now my question is, shall i better define the variables outside of this repeating code (outside this timer?) or doesntit matter at all?
Cause right now it is included in the timer with all the other code and that would mean it is redefined every second, right?

So should i better do it like this or doesnt it matter?

pawn Код:
//On top of script
new rhour,rminute,rsecond;
new stringt[22],stringts[10];

forward Timer1Sec();
public Timer1Sec()
{
        gettime(rhour,rminute,rsecond);
        format(stringt,sizeof stringt,"~y~%d~w~:~y~%d",rhour,rminute);
        TextDrawSetString(RealTime,stringt);
        format(stringts,sizeof stringts,"~w~%d",rsecond);
        TextDrawSetString(RealTimeS,stringts);
        return 1;
}

Would be happy about help and also rep+
Reply
#2

Tested both methods:

Код:
[01:57:02] Method 1 finished in: 112ms
[01:57:02] Method 2 finished in: 117ms
[01:57:03] Method 1 finished in: 106ms
[01:57:03] Method 2 finished in: 116ms
[01:57:04] Method 1 finished in: 114ms
[01:57:04] Method 2 finished in: 114ms
[01:57:05] Method 1 finished in: 119ms
[01:57:05] Method 2 finished in: 124ms
[01:57:06] Method 1 finished in: 110ms
[01:57:06] Method 2 finished in: 115ms
[01:57:07] Method 1 finished in: 116ms
[01:57:07] Method 2 finished in: 121ms
Method 1 = variables defined on top of script
Method 2 = variables defined inside the timer

If I helped, rep me
Reply
#3

It's same. But, why you cant use gl_realtime ? Comming with samp server
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)