Looping all vehicles using foreach
#1

hello guys i am new to foreach so its my first time i made this, and i decided to use foreach as many people say its easy and much better than and much less CPU Usage

pawn Код:
for (new i = 0; i <MAX_VEHICLES; i++)

or

for (new i = 0; i <MAX_PLAYERS; i++)
so i am asking how to loop a vehicle using foreach? i've tried using ****** code on example but it give's me error

here's my code
pawn Код:
new Iterator:Vehicles<MAX_VEHICLES>; // global variable
foreach(new vehicleid : Vehicles)
{
//Loop through all the vehicles and set their fuel levels at DEF_GAS
CarFuel[vehicleid] = DEF_GAS;//gives 100% gas to all vehicles
}
and give's me warning

pawn Код:
warning 203: symbol is never used: "Vehicles@YSII_Cg"
Reply
#2

Well do you ever use Iter_Add?
Reply
#3

Quote:
Originally Posted by pds2012
Посмотреть сообщение
many people say its easy and much better than and much less CPU Usage
If you're not deleting vehicles and if you know how many vehicles there are, then a plain loop is still faster. Looking up the next id - in whatever weird tree system ****** created - still takes a little time.
Reply
#4

@ LarzI i did not use Iter_add

@Vince i tried using someone's code and tried doing this and remove's the warning but it seems not working properly, i used grand larcenary Los Santos vehicles which is this

pawn Код:
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_law.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_airport.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_gen_inner.txt");
total_vehicles_from_files += LoadStaticVehiclesFromFile("vehicles/ls_gen_outer.txt");
and removed some vehicles all vehicles i have atm on the server is 546

pawn Код:
static stock
    Iterator:Vehicles<MAX_VEHICLES>
;
Reply
#5

Thanks
******, i understand it
thanks alot Vince and LarzI
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)