optimize code
#1

resolvi smd..
Reply
#2

I don't think that removing { } would optimize your code, it might make it 'look' better for some people however, I think it doesn't affect that much in performance. Moreover, some people find this a cause for confusion due to you can remove the { } once there's one operation/function whatever to be done. For instance,

pawn Code:
if(Carlos == "good")
foreach(new i : Player)
{
      SendClientMessage(i, -1, "CARLOS IS GOOD!");
}
This is not a must!
Reply
#3

Not quite understand, but I'll try ..

@edit
I did not make it.. please
Reply
#4

Quote:
Originally Posted by DeadNudock
View Post
I tried to let the faster code, let easier to understand, more can not, please someone can tell me how I can remove the

PHP Code:
{} 
without harming the code?

PHP Code:
                    if (IsGangueGRI(i))
                    {
                        if (
PlayerInfo[i][pCargo] == 1)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc1] == 0)
                            {}
///
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 2)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc2] == 0)
                            {}
/////
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc2])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc2];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc2]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 3)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc3] == 0)
                            {}
////
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc3])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc3];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc3]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 4)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc4] == 0)
                            {}
////
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc4])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc4];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc4]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 5)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc5] == 0)
                            {}
///
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc5])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc5];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc5]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 6)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][Dinheiro] >= 2000PlayerInfo[i][pSalario] += 2000SacarGranaOrg(GetPlayerOrg(i), 2000);
                        }
                    } 
PHP Code:
if (CofreOrg[GetPlayerOrg(i)][salarioc1] == 0
{}
/// 
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1]) 
 { 
          
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1]; 
           
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]); 
 } 
// Change to
if (CofreOrg[GetPlayerOrg(i)][salarioc1] != && CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1]) 
 { 
          
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1]; 
           
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]); 
 } 
Reply
#5

You could also change the whole thing into a switch statement which would be a lot nicer to read

PHP Code:
if (IsGangueGRI(i)) 
{
    switch(
PlayerInfo[i][pCargo]){
    case 
1:
        if (
CofreOrg[GetPlayerOrg(i)][salarioc1] != && CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])  
        {  
            
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];  
            
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);  
        }  
     case 
2:
          
// next section
      
case 3:
           
// etc
    
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)