Posts: 3,934
Threads: 353
Joined: Jan 2010
Reputation:
0
Well, I'd like to know which one I should actually be using.
For example, i'm creating a register function, and want to declare a Query variable, would I use "static" or "new"?
Posts: 2,262
Threads: 260
Joined: Mar 2009
Reputation:
0
afaik static is something that must stay in the part that you've coded it to.
If you created an include and added some statics variables, the gamemode cannot use those variables as they're only usable in the include.
Posts: 3,934
Threads: 353
Joined: Jan 2010
Reputation:
0
Ah right, so it can be static when it's inside a stock function? I am only using the variable inside that stock function.
Also does it reduce the amx file size?
Posts: 11,827
Threads: 33
Joined: Dec 2011
Reputation:
0
Yes, it can be used inside a function and it's called static local. It also "holds" its old value.
I'm not aware of whether it reduces the size of the .amx or not.
Posts: 966
Threads: 5
Joined: Jul 2011
Reputation:
0
About the size -- it isn't important at all. The static keyword serves other purposes. newbienoob already mentioned one usage: keeping the variable inside its file. Keeping a variable known in only a function's scope is beneficial when working on large or confusing code, it leaves you less room for error.
Its function is that its value is kept. It is not stored on the stack and very speaking by a simplified model of memory management, it is as fast as any other global variable (which are in the data segment of some sort, on the heap).
But please do find the keyword useful.