SA-MP Forums Archive
Scriptors come hier! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Scriptors come hier! (/showthread.php?tid=643008)



Scriptors come hier! - kAn3 - 11.10.2017

PHP код:
new K[MAX_PLAYERS] = {0,...}; 
What does this exactly mean?


Re: Scriptors come hier! - Kyle - 11.10.2017

The {0, ...} tells the compiler to set all of the array index values to 0.

For example if you accessed the 5th index, the value would be 0. The ... means recurring.

This code is redundant as all index values are already automatically set to 0.


Re: Scriptors come hier! - kAn3 - 11.10.2017

So it is like doing
PHP код:
new K[MAX_PLAYERS];
for(new 
0MAX_PLAYERSi++)K[i] = 0
?


Re: Scriptors come hier! - Kyle - 11.10.2017

Quote:
Originally Posted by kAn3
Посмотреть сообщение
So it is like doing
PHP код:
new K[MAX_PLAYERS];
for(new 
0MAX_PLAYERSi++)K[i] = 0
?
Kind of...

You can only define the code once so you cannot do this more than once:

Код:
new K[MAX_PLAYERS] = {0,...};
You can only do it when declaring the variable array.
So if you wanted to change all values to 0 at anytime then you execute your code above.


Re: Scriptors come hier! - kAn3 - 11.10.2017

Thanks!
+Rep


Re: Scriptors come hier! - Prokill911 - 11.10.2017

Lol, who ever added that line of code was drunk because it's a null statement to a preexisting statement


Re: Scriptors come hier! - kAn3 - 11.10.2017

What do you mean?


Re: Scriptors come hier! - whadez - 11.10.2017

Quote:
Originally Posted by Prokill911
Посмотреть сообщение
Lol, who ever added that line of code was drunk because it's a null statement to a preexisting statement



Re: Scriptors come hier! - whadez - 11.10.2017

It means that when you declare a variable which has a type that contain numbers (int, boolean in our case) their default value will be (0). Therefore setting it's default value to (0) is useless. When you declare a variable which has characters in it (string), their values are NULL for each and every character.


Re: Scriptors come hier! - BigETI - 12.10.2017

Arrays in PAWN are initialized to zero by default.