22.07.2011, 11:42
Global static variables:
Assume you have
Now you include MyInclude in your gamemode.
The difference is now that you can use MyGlobalVar in your gamemode but you can't use MyStaticVar because it can only be used in the file where it's declared.
---
Local static variables are like global variables BUT the can only be used in the function where the get declared.
Local static variables do NOT get deleted/reset after the function has been performed.
Example:
Assume you have
pawn Код:
static MyStaticVar = 4; // in the file MyInclude1.inc
// and the variable
new MyGlobalVar = 5;
The difference is now that you can use MyGlobalVar in your gamemode but you can't use MyStaticVar because it can only be used in the file where it's declared.
---
Local static variables are like global variables BUT the can only be used in the function where the get declared.
Local static variables do NOT get deleted/reset after the function has been performed.
Example:
pawn Код:
MyFunc1 ()
{
static var1 = 0;
var1++;
printf ("var1 = %d", var1); // Will print 1, 2, 3, 4 => Will increase by 1 everytime the function gets called.
}
MyFunc2 ()
{
new var2 = 0;
var2++;
printf ("var2 = %d", var2); // Will ALWAYS print 1
}