Raised This Month: $32 Target: $400
 8% 

Bracketing in a for loop?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 09-20-2017 , 14:13   Bracketing in a for loop?
Reply With Quote #1

Would this be correct?

PHP Code:
    for    (new 1<= MaxClientsi++)
        if    (
IsClientInGame(i) && bIsPlayerAlive[i] && bIsPlayerZombie[i])
        {
            
SetEntityRenderColor(i255255255255);
            
TF2_ChangeClientTeam(iTFTeam_Blue);
            
TF2_RegeneratePlayer(i);
            
CreateTimer(0.3RespawnPlayeri);
        }
        else if (
IsClientInGame(i) && bIsPlayerAlive[i] && !bIsPlayerZombie[i])
            
CreateTimer(0.3RespawnPlayeri);
        
CreateTimer(0.3ResetRound); 
or this

PHP Code:
    for    (new 1<= MaxClientsi++)
        {
        if    (
IsClientInGame(i) && bIsPlayerAlive[i] && bIsPlayerZombie[i])
        {
            
SetEntityRenderColor(i255255255255);
            
TF2_ChangeClientTeam(iTFTeam_Blue);
            
TF2_RegeneratePlayer(i);
            
CreateTimer(0.3RespawnPlayeri);
        }
        else if (
IsClientInGame(i) && bIsPlayerAlive[i] && !bIsPlayerZombie[i])
            
CreateTimer(0.3RespawnPlayeri);
        }
        
CreateTimer(0.3ResetRound); 
Halt is offline
fiction
Member
Join Date: May 2017
Old 09-20-2017 , 14:20   Re: Bracketing in a for loop?
Reply With Quote #2

I believe it's just preference, so you can use whichever looks better to you. The SourceMod contributing guidelines says to always use braces for block statements, so if you want to follow that standard you can. https://wiki.alliedmods.net/Contribu...d#Coding_Style
fiction is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-20-2017 , 18:52   Re: Bracketing in a for loop?
Reply With Quote #3

Tbh those both look horrible.

Code:
public void SomeFuntion()
{
   for (int client=1; client <= MaxClients; client++)
   {
      if (!IsClientInGame(client))
         continue;

      // code goes here
   }
}
__________________
Neuro Toxin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-21-2017 , 14:49   Re: Bracketing in a for loop?
Reply With Quote #4

You do multiple timers (ResetRound) for purpose ? Spawning and ResetRound ?

PHP Code:
...
{
     for (new 
1<= MaxClientsi++)
     {
        if(!
IsClientInGame(i) || !IsPlayerAlive(i)) continue;

        if(
bIsPlayerZombie[i])
        {
            
SetEntityRenderColor(i255255255255);
            
TF2_ChangeClientTeam(iTFTeam_Blue);
            
TF2_RegeneratePlayer(i);
            
CreateTimer(0.3RespawnPlayeri);
        }
        else
        {
            
CreateTimer(0.3RespawnPlayeri);
        }
     }
     
     
CreateTimer(0.3ResetRound); 
 } 

*edit
not sure does your variable bIsPlayerAlive[i] match with native IsPlayerAlive...
__________________
Do not Private Message @me

Last edited by Bacardi; 09-21-2017 at 14:52.
Bacardi is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-21-2017 , 16:52   Re: Bracketing in a for loop?
Reply With Quote #5

That awful whitespace you place between "if"/"for" and "(" hurts my brain.

Bad:
Code:
for    (int client; ...)
Good:
Code:
for (int client; ...)
__________________
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:58.


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