SA-MP Forums Archive
Foreach with iterator - 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: Foreach with iterator (/showthread.php?tid=658074)



Foreach with iterator - GospodinX - 22.08.2018

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?


Re: Foreach with iterator - GospodinX - 24.08.2018

bump...


Re: Foreach with iterator - None1337 - 24.08.2018

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);




Re: Foreach with iterator - GospodinX - 24.08.2018

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.


Re: Foreach with iterator - GospodinX - 24.08.2018

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!