SA-MP Forums Archive
Using local statics - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Using local statics (/showthread.php?tid=625152)



Using local statics - BiosMarcel - 28.12.2016

Hello,

I have never ever used statics, so i was asking myself if i could do this, furthermore, what would you say is better?
So for example, i have this code:

PHP код:
    for(new 0sizeof(deadPlayers); ji++)
    {
        
deadPlayers[i] = "";
    } 
I am using this code to clear all strings in an array.
Looking at this code we can see, that every time it is called the size of "deadPlayers" will be retrieved.
So, if this code would be called very often (let us just say 200 times a second), should i do this instead?:

PHP код:
    static deadPlayersSize sizeof(deadPlayers);
    for(new 
0deadPlayersSizei++)
    {
        
deadPlayers[i] = "";
    } 
Just an example tho, no productive code


Re: Using local statics - Vince - 28.12.2016

Sizeof is an operator, not a function. The value only gets calculated once at compile time.


Re: Using local statics - BiosMarcel - 28.12.2016

Oh, good to know , thanks