Simple MAX_PLAYERS question
#1

Код:
new var;

new var[MAX_PLAYERS];
Whats the difference between these 2? As I heard, "[MAX_PLAYERS]" is more for one specific player... Can you explain in more detail?
Reply
#2

As far as i know,
The first one Is a global variable that can be assigned a value , and it only has 1 value always. so if you change it anywhere in the script it will be that value.

the 2nd one, is a global variable that is attatched to a player, When you change the value it will only change for that player. not for everyone.
Reply
#3

The first line is a regular variable, whereas the second one is an array.

[MAX_PLAYERS] (default size of 500) is simply the size of the variable. It can be anything as long as it holds a value.

https://sampwiki.blast.hk/wiki/Scripting_Basics#Variables
https://sampwiki.blast.hk/wiki/Scripting_Basics#Arrays
Reply
#4

"new var" is one storage, "new var[MAX_PLAYERS];" is storage for each player, it's called an array
Read This
Reply
#5

If you use the first, you will be able to store one value in that one variable.

If you use the second, you will be able to store a value for every player in your server. This type of variable is called an array. You can access it by doing:

PHP код:
new Money[MAX_PLAYERS];
Money[playerid] = 500
You can then set a variable per individual player: useful for other systems.
Reply
#6

Ok, thanks, now other question. MAX_PLAYERS define 500, yes? So, does it will be the same if I do

Код:
new var[500];
Reply
#7

Yes, its the same - but its recommended to use MAX_PLAYERS.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)