Info of local variable and global
#1

Hey guys. I know this isn't a great issue but yes if you use them in wrong way it may cause a big problem.
So i wanted to know that ,

If I use something like the below codes, first let's see the code.

Код:
new example[MAX_PLAYERS];
In this codes the example value of each player will be stored for every single player right?
Or it will be stored for all the players in-game?
I mean if i type
Код:
//In some context cmd
example[playerid] = 10;
Here will it be saved for only the player who used the cmd? Or for all?

And the second question is for the same purpose :
Код:
new example;
Now the example value what ever is stored will be for all?

Thank you. Please guide me here.
Reply
#2

PHP код:
CMD:lol(playeridparams[])
{
   
example[playerid] = 10;
   return 
1;

This will be just for the player to type the CMD.
PHP код:
CMD:lol(playeridparams[])
{
   
example 10;
   return 
1;

This will be for everyone
Reply
#3

Quote:
Originally Posted by saffierr
Посмотреть сообщение
PHP код:
CMD:lol(playeridparams[])
{
   
example[playerid] = 10;
   return 
1;

This example is good. The player who typed the command /lol set the value example to 10 for his ID.
-If I'm a player ID 9 and I type the command /lol, so example[9] = 10.
So when a player disconnect you need to reset the variable (by player's id).
I hope you understand this.
Reply
#4

Fistly thats not what meant by local and global variables
secondly yes and yes to both of ur questions as the array in first case have cells fir each playerid so it will be for each player and in the second var yeah it will be for whole concept of server as its single var with no allocated space
Reply
#5

As Dayrion mentioned, don't forget to reset the variables on OnPlayerDisconnect, or else if you by example, mute ID 9, the next ID 9 will be muted too.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)