foreach problem
#1

pawn Код:
foreach(Vehicle, vehicleid)
{
     DestroyVehicleEx(vehicleid);
}

DestroyVehicleEx(vehicleid)
{
     Itter_Remove(Vehicle, vehicleid);
     DestroyVehicle(vehicleid);
}
I use this for destroying certain admin spawned vehicles, (of course this isn't my exact code) but it sends an "Unknown command" error when I use the CMD, and it only destroys the first car. This works perfectly when I remove the "Itter_Remove" function out of my DestroyVehicleEx, and this also works when I used the old fashon looping, so i'm pretty sure it's not working since i'm removing an itter in the middle of a foreach loop, any solutions for this?
Reply
#2

you have to use Safe itter remove function


the problem is you remove the itter while the loop is still looping,
changing the loop and breaking your code,
look in the foreach topic this is covered
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)