Whats better and why - 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: Whats better and why (
/showthread.php?tid=665173)
Whats better and why -
NoteND - 24.03.2019
Hey!
I'm just wondering if there is any difference between
PHP Code:
for(new j = GetPlayerPoolSize(), i = 0; i <= j; i++)
and
PHP Code:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
And if there is, whats the difference and whats better to use?
EDIT: And do you need to use "if(IsPlayerConnected(i))" after using GetPlayerPoolSize, since getplayerpoolsize only gets online players ?
Thanks for help!
Re: Whats better and why -
SymonClash - 24.03.2019
https://sampforum.blast.hk/showthread.php?tid=581727
Re: Whats better and why -
Heress - 24.03.2019
Use foreach, i think it is the best choice.
Re: Whats better and why -
NoteND - 24.03.2019
Okay thanks
Re: Whats better and why -
Gammix - 24.03.2019
There's no difference. And yes you need to use
IsPlayerConnected inside the loop because
https://sampwiki.blast.hk/wiki/GetPlayerPoolSize
So you still need to check the ids are connected to the server.
And on another note, foreach is faster and better.