Foreach with iterator
#1

Hi guys,

I'm begin to work with iterator's,so I think that i'm doing something wrong.I use iterator for player's vehicle.(List of player's vehicles) I have problem with foreach.

Код:
new Iterator: Vehicles[MAX_PLAYERS]<MAX_CAR>;
OnPlayerDisconnect (There I destroy vehicles..)
Код:
foreach(new i: Vehicles[playerid])
{
DestroyVehicle(VehicleInfo[i][vID]);
printf("%d %d",i, playerid);
}
Server_log: http://prntscr.com/klmj0d (So my server spam, i = 0 and i don't know why he don't want to get out from loop(Foreach).I think it spam when player don't have any vehicle.
For now,I'm do this:

Код:
new number = Iter_Count(Vehicles[playerid]);
if(number > 0)
{
foreach...
It work's now.But i'm not sure do I need to check player vehicles before foreach loop?
Reply
#2

bump...
Reply
#3

Did you add Iter_Init(Vehicles); in OnGameModeInit?

Also, you can use this:

PHP код:
foreach(new iVehicles[playerid])
{
             
printf("%d %d",iplayerid);
             
printf("[debug] destroying vehicle %i"VehicleInfo[i][vID]);
             
DestroyVehicle(VehicleInfo[i][vID]);
             
Iter_SafeRemove(Vehicles[playerid], ii);

Reply
#4

No.I don't use Iter_Init anytime in my gamemode.I need to add this for every iterator which I use on OnGameModeInit?

I use this when player log in:
Iter_Add(Vehicles[playerid], id_vozila);
But just if player have vehicles.
Reply
#5

Quote:

Again, if you’re using the latest version of the include you should get a warning along the lines of symbol is never used "Iter_Init@Vehicles".

Now I'm download latest version but I'm not getting any warning
I will add it,thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)