static gTeam[MAX_PLAYERS]?
#1

Hello,

My question is simple: what does that static do? What is different from a simple new ?

Regards, Jochem
Reply
#2

https://sampwiki.blast.hk/wiki/Scripting...s#static_local Explains it pretty much
Reply
#3

Actually it doesn't explain at all what just a simple static is.
Reply
#4

Ok, heres one of the examples at the wiki:

pawn Код:
for (new i = 0; i < 3; i++)
{
    static
        j = 1;
    printf("%d", j);
    j++;
}
That would print 1,2,3 as it loops the FOR 3 times. why it wont just print 1,1,1 as a local var would is cause it remembers its old value.

Explaining enough?
Reply
#5

Simple test example.
pawn Код:
for(new i = 0; i < 3; i++)
{
    static j = 1;
    printf("%d",j);
    j++;
}
Printed:
Quote:
Originally Posted by samp-server.exe- server_log.txt
[16:38:50] 1
[16:38:50] 2
[16:38:50] 3
As:
pawn Код:
for(new i = 0; i < 3; i++)
{
    new j = 1;
    printf("%d",j);
    j++;
}
Printed:
Quote:
Originally Posted by samp-server.exe- server_log.txt
[16:38:50] 1
[16:38:50] 1
[16:38:50] 1
Reply
#6

https://sampwiki.blast.hk/wiki/Keywords:Initialisers#static

Quote:

A static variable is like a global new variable but with a more limited scope. When static is used globally the resulting created variables are limited to only the section in which they were created.

Reply
#7

I still don't get it.. How bad of me I dont know this basic thing.
Reply
#8

Wiki: Global static variables are like normal globals but can only be used in the file in which they are declared
Reply
#9

So what is the point of using gTeam with this?
Reply
#10

They're only really useful if you have more than one file in your sourcecode. If you plonk your gamemode all into the one file like most people then you don't have to worry about them.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)