[Help] Simple LITTLE question.
#8

Quote:
Originally Posted by moadi
Посмотреть сообщение
Hey,
I'm new at pawno scripting and still learning it .

I've seen this many times and i still don't know what it means :

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Could anyone please explain me what does it exactly mean and what is it used for? i'm pretty sure it's something i must know

Thanks in advance .
Imagine that. Your MAX_PLAYERS define variabile it's setted to 500. You have to check each player to do something for it. To check if a player it's on server, you must use the IsPlayerConnected function.
Let's say you have 4 players connected:
Player ID 0: Jack
Player ID 1: Dean
Player ID 2: Paul
Player ID 3: Sam
The rest of slots are empty slot. So, to don't check each player in 500 lines, like:
PHP код:
if(IsPlayerConnected(0)) /* Do code */
if(IsPlayerConnected(1)) /* Do code */
if(IsPlayerConnected(2)) /* Do code */
if(IsPlayerConnected(3)) /* Do code */
if(IsPlayerConnected(4)) /* Do code */
/*..................................*/
if(IsPlayerConnected(99)) /* Do code */
if(IsPlayerConnected(100)) /* Do code */
/*..................................*/
if(IsPlayerConnected(300)) /* Do code */
if(IsPlayerConnected(301)) /* Do code */
/*..................................*/
if(IsPlayerConnected(499)) /* Do code */
if(IsPlayerConnected(500)) /* Do code */ 
You can do that with for loop:
PHP код:
for(new 0MAX_PLAYERSi++)
    if(
IsPlayerConnected(i))
        
/* Do code */ 
First, he checks the first index, = 0. After that, the for loop checks the next index, by incrementing variabile i to 1 ( i++ = (i = i + 1) = (i += 1) ). When i = MAX_PLAYERS, the for loop is break.
Reply


Messages In This Thread
[Help] Simple LITTLE question. - by moadi - 06.10.2011, 17:50
Re: [Help] Simple LITTLE question. - by IstuntmanI - 06.10.2011, 18:24
Re: [Help] Simple LITTLE question. - by moadi - 06.10.2011, 18:28
Re: [Help] Simple LITTLE question. - by System64 - 06.10.2011, 18:52
Re: [Help] Simple LITTLE question. - by [HiC]TheKiller - 06.10.2011, 19:16
Re: [Help] Simple LITTLE question. - by Kingunit - 06.10.2011, 19:27
Re: [Help] Simple LITTLE question. - by spd_sahil - 06.10.2011, 19:41
Re: [Help] Simple LITTLE question. - by MoroDan - 06.10.2011, 19:55

Forum Jump:


Users browsing this thread: 6 Guest(s)