AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   For cycle (https://forums.alliedmods.net/showthread.php?t=173842)

KamiN 12-11-2011 06:20

For cycle
 
Witch one is better??

Code:

    new name[33]; get_user_name(id, name, charsmax(name))
 
    for(new i = 1; i < g_max_clients; i++)
    {

To give a gun to a player i would have to write
Code:

give_item(i, "weapon_deagle")


--

Code:

    new players[32], num
 
    get_players(players, num, "a")  // It returns all alive players? I mean both teams, CTs and Ts?

 
    for(new i; i < num; i++)
    {

To give a gun to a player i should write this
Code:

give_item(players[i], "weapon_deagle")



or this
Code:

give_item(i, "weapon_deagle")

?




Kidev 12-11-2011 08:02

Re: For cycle
 
PHP Code:

static iPlayers32 ], iNumtid;
get_playersiPlayersiNum"a" );
for ( new 
0iNumi++ )
{
    
tid iPlayers]; // You can also use iPlayers[ i ], but if you use it more than one time, cache the value in a variable.
    
give_itemtid"weapon_deagle" );



KamiN 12-11-2011 08:59

Re: For cycle
 
Whats the difference betwen

Code:

new i
and
Code:

new i = 0
?

drekes 12-11-2011 10:02

Re: For cycle
 
Quote:

Originally Posted by KamiN (Post 1611314)
Whats the difference betwen

Code:

new i
and
Code:

new i = 0
?

Nothing, some programming languages (c++ too i think) require to be initialized when they are created. Pawn doesn't require it but some people do it out of habit.
Pawn initialized at 0, so there is no difference in this case.

Kidev 12-11-2011 11:27

Re: For cycle
 
Quote:

Originally Posted by drekes (Post 1611340)
Nothing, some programming languages (c++ too i think) require to be initialized when they are created. Pawn doesn't require it but some people do it out of habit.
Pawn initialized at 0, so there is no difference in this case.

Yeah, I set it to 0 to be clear.


All times are GMT -4. The time now is 12:05.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.