static gTeam[MAX_PLAYERS]? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: static gTeam[MAX_PLAYERS]? (
/showthread.php?tid=174349)
static gTeam[MAX_PLAYERS]? -
Jochemd - 05.09.2010
Hello,
My question is simple: what does that static do? What is different from a simple new ?
Regards, Jochem
Re: static gTeam[MAX_PLAYERS]? -
Cameltoe - 05.09.2010
https://sampwiki.blast.hk/wiki/Scripting...s#static_local Explains it pretty much
Re: static gTeam[MAX_PLAYERS]? -
Jochemd - 05.09.2010
Actually it doesn't explain at all what just a simple static is.
Re: static gTeam[MAX_PLAYERS]? -
Cameltoe - 05.09.2010
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?
Re: static gTeam[MAX_PLAYERS]? -
[XST]O_x - 05.09.2010
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
|
Re: static gTeam[MAX_PLAYERS]? -
Calgon - 05.09.2010
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.
|
Re: static gTeam[MAX_PLAYERS]? -
Jochemd - 05.09.2010
I still don't get it.. How bad of me I dont know this basic thing.
Re: static gTeam[MAX_PLAYERS]? -
Vince - 05.09.2010
Wiki: Global static variables are like normal globals but can only be used in the file in which they are declared
Re: static gTeam[MAX_PLAYERS]? -
Jochemd - 05.09.2010
So what is the point of using gTeam with this?
Re: static gTeam[MAX_PLAYERS]? -
Jay_ - 05.09.2010
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.