foreach and 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 and loop? (
/showthread.php?tid=650788)
foreach and loop? -
ivndosos - 06.03.2018
What's the difference between foreach and for(new ?
Re: foreach and loop? -
RxErT - 06.03.2018
foreach is more faster than the normal loop (that's my knowledge about this)
Re: foreach and loop? -
ivndosos - 06.03.2018
alright, another question
when I use this
Код:
foreach(new i : pInfo)
I get these errors
Код:
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1211) : error 017: undefined symbol "Iterator@pInfo"
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1211) : warning 215: expression has no effect
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1211) : error 001: expected token: ";", but found ")"
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1211) : error 029: invalid expression, assumed zero
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1211) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
But when I replace "pInfo" with Player it compiles ?
Re: foreach and loop? -
AroseKhanNiazi - 06.03.2018
Foreach will only go through online Players, that's why it is faster. Foreach include has many other advantages too not just player's loop. Other loops, well that you can do in any way you like.
PHP код:
foreach(new i : Player)
Re: foreach and loop? -
v1k1nG - 07.03.2018
pInfo and Player are two completely different things, as pInfo could be an array, and Player means any playerid of connected players.