converting normal loop to foreach.
#1

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 !
Reply
#2

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;
}
Reply
#3

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

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

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 ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)