View Full Version : Question about 'static'

24/07/2013, 03:07 PM
I only recently learned that they "static" variables don't loose their value between calls.

And i instantly thought: gates! They're just perfect for them! Becaus I hate having global variables for them...

But someone should have thought of that....

Getting to the question part,
are there downsides to them? Are they somehow worse than global ones? Should I or should I not use them?

ANY feedback will be appreciated :)

24/07/2013, 03:09 PM
I'm my opinion I wouldn't use them, they are a hastle. -- But it's what you want to.

24/07/2013, 03:27 PM
I'm my opinion I wouldn't use them, they are a hastle. -- But it's what you want to.

That's the thing, i want a reason, why wouldn't you use them?

24/07/2013, 03:39 PM
I just think they are a inconvenience.

25/07/2013, 04:41 PM

25/07/2013, 04:48 PM
Static variables are global variables that you can use only in specific block.
If you want to make a global variable that exists only between { and } use static.
If you want to use the variable outside use normal global.
I would use static for gates. Why? When I use static, outside the block I can declare another variable with same name without getting warnings.

25/07/2013, 04:52 PM
static variables are almost the same thing was local variables, the unique difference is that the variable is not deleted after executing the function, so, you can use the content of the variable when you run that function again. [talking about the static local]

@Edit -> http://wiki.sa-mp.com/wiki/Scripting_Basics#static_local

25/07/2013, 05:05 PM
Also global static exists only for single file, and won't be visible in other files namespace