Little question about static
#1

I download the GAdmin admin system by Gammix, but i saw he used alot of static variabiles , like this:
Код:
static string[250];

	if (!text[0])
	{
	    format(string, sizeof (string), ""COL_WHITE"Write your message to "COL_LIGHT_BLUE"%s[%i] "COL_WHITE"(admin level %i | vip level %i)", ReturnPlayerName(targetid), targetid, p_Account[targetid][E_ACCOUNT_ADMIN_LEVEL], p_Account[targetid][E_ACCOUNT_VIP_LEVEL]);
		return Dialog_Show(playerid, DIALOG_PRIVATE_MESSAGE, DIALOG_STYLE_INPUT, "Private messaging...", string, "Send", "Cancel");
	}
It's have an effect on the format? Or what? I mean , the static variabiles can be changed only from script and can't be changed in runtime.....
So why? I try to find the answer , but i can't find it...so i ask you
Reply
#2

https://sampwiki.blast.hk/wiki/Scriptin...s#static_local

Basically:

"Because j is static so remembers its old value."
Reply
#3

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
I I mean , the static variabiles can be changed only from script and can't be changed in runtime.....
You're confusing it with const.

A static local remembers its value between successive function calls, in contrast to regular "new" variables which are discarded when the function ends. Then again, if a static local is overwritten each time then it serves little to no use.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
You're confusing it with const.

A static local remembers its value between successive function calls, in contrast to regular "new" variables which are discarded when the function ends. Then again, if a static local is overwritten each time then it serves little to no use.
It is also used in encapsulation when making includes since you usually don't want to give access to essential data.
Reply
#5

The local static variable used there is useless since it's used only for a string to be formatted. It's previous values or data is never considered so it's pointless. Local variables do not interfere with other scripts, so normal variables would've been fine.

I mostly use static variables for developing includes, it provides data abstraction in addition to what the above posts say.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)