SA-MP Forums Archive
foreach loop - 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 loop (/showthread.php?tid=528418)



foreach loop - Don_Cage - 27.07.2014

So..
If I want to loop through all my "DsVeh" can I do it with foreach instead of that other for(new blahblahblah.. ??
If yes, how? I tried with
pawn Код:
foreach(DsVeh, i)
but that obviously didn't work lol


Re: foreach loop - Threshold - 27.07.2014

What is DsVeh, can you show where you use/apply/define it?


Re: foreach loop - Don_Cage - 27.07.2014

pawn Код:
new DsVeh[sizeof(cInfo)];
and my cInfo
pawn Код:
enum CarInfo
{
    Owner[MAX_PLAYER_NAME],
    Owned,
    Color,
    Color2,
    Float: Pos_X,
    Float: Pos_Y,
    Float: Pos_Z,
    Float: Angle,
    Price
}
new cInfo[MAX_VEHICLES][CarInfo];



Re: foreach loop - Don_Cage - 28.07.2014

With the "old" loop you could just do
pawn Код:
for(new i = 0; i < sizeof(DsVeh); i++)
But I'm making a roleplay gamemode from scratch so I would like everything to be the same. Not just randomly use for(new on some things and foreach on some. It looks better with only using one system and to be honest I'm kinda a freak about everything being exact..


Re: foreach loop - BroZeus - 28.07.2014

go to https://sampforum.blast.hk/showthread.php?tid=92679
and see its declaration and functions section