SA-MP Forums Archive
Cikle in foreach. - 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: Cikle in foreach. (/showthread.php?tid=494992)



Cikle in foreach. - audriuxxx - 15.02.2014

Hi,

Can i do cikle in foreach?

Код:
foreach(new i : Player)
{
for(new x = 0; x < MAX_PLAYERS; x ++)
{

}
}



Re: Cikle in foreach. - Konstantinos - 15.02.2014

I don't get what you mean. Cikle is supposed to be loop? It's used as:
pawn Код:
foreach(new i : Player)
{
    // code for player with playerid equal to i
}



Re: Cikle in foreach. - audriuxxx - 15.02.2014

No... First i will do foreach, to search a player, and then i need do another cikle, to search another players with another variables.


Re: Cikle in foreach. - Konstantinos - 15.02.2014

So you want to check about 2 players at the same time?

pawn Код:
foreach(new i : Player)
{
    foreach(new j : Player)
    {
        // Player i and Player j.. do something..
    }
}



Re: Cikle in foreach. - audriuxxx - 15.02.2014

Yea like that. But when i use 2 foreach like that my server get off.


Re: Cikle in foreach. - Konstantinos - 15.02.2014

You mean the server shuts down? Load crashdetect plugin and compile with debug info. Re-compile your scripts and run the server. If it stops again, post the server log.

I've used double foreach in the past and I had no problems with it.