SA-MP Forums Archive
converting normal loop to 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: converting normal loop to foreach. (/showthread.php?tid=405323)



converting normal loop to foreach. - [D]ry[D]esert - 06.01.2013

Hello every one.
How do i convert this normal loop to foreach ?
pawn Код:
for(new x; x<MAX_PICKUPS; x++)
                    {
                    if(IsPlayerInRangeOfPoint(i,1,NITRO[x][Pos][0],NITRO[x][Pos][1],NITRO[x][Pos][2]))
                    {
                        if(IsPlayerInAnyVehicle(i))
                            {
                                AddVehicleComponent(GetPlayerVehicleID(i),1010);
                            }
                    }
                    }
Thanks for reading !


Re: converting normal loop to foreach. - Konstantinos - 06.01.2013

You can only use foreach to loop through all the Pickups only if you've created an Iterator for all the created pickups. But you can use foreach for players.
pawn Код:
foreach (new i : Player)
{
    // code;
}



Re: converting normal loop to foreach. - [D]ry[D]esert - 06.01.2013

I know about players but i mean about
pawn Код:
#define MAX_REPAIRS 30
can i loop with that using foreach without using y_iterate.


Re: converting normal loop to foreach. - Konstantinos - 06.01.2013

No, you cannot. You should declare an iterator for using foreach through all the created REPAIRS/PICKUPS or whatever else you want.


Re: converting normal loop to foreach. - [D]ry[D]esert - 06.01.2013

Quote:
Originally Posted by Dwane
Посмотреть сообщение
only if you've created an Iterator for all the created pickups. But you can use foreach for players.
so if i got more than 100 pickup
that will take long time to Iterator them all.
and faster way ?