26.11.2015, 15:24
Quote:
Depending on where the variable is declared, the meaning of static changes.
In Pawn, if a variable is declared static in the global space then it functions exactly like a normal ("new") global variable, with the key exception that it is only visible in the file that it was declared in. This is useful for includes as the main gamemode file won't be able to access it, and other (include) files can use the same variable name without conflict. If a variable is declared static within the local scope then it will be kept in memory and it will retain its value between function calls. Normal variables are immediately disposed of when the function ends. In that sense, a static local is useful when you require a global that is only used within that one function. |
Код:
stock function() { static a =50; a++; print("%d", a); } function(); function();
see i used "function();" two times, that means the first time it will return 50 + 1 = 51 and then, it will return the second time 52 because it kept "51" and it added 1 after
am i right?
and one little question, can we use static for strings?
thanks in advance