AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optimize help (https://forums.alliedmods.net/showthread.php?t=173454)

Larcyn 12-05-2011 11:23

Optimize help
 
Hello, is it possible to optimize this code?

PHP Code:


if(iRPS[iPlayer] == && iRPS[iTarget] == 2)
{
//Action here
}
    
if(
iRPS[iPlayer] == && iRPS[iTarget] == 3)
{
//Action here
}
    
if(
iRPS[iPlayer] == && iRPS[iTarget] == 1)
{
//Action here
}
    
if(
iRPS[iPlayer] == && iRPS[iTarget] == 1)
{
 
//Action here


If yes, how could it be done
Thanks in advance

Xalus 12-05-2011 11:28

Re: Optimize help
 
PHP Code:


if( iRPS[iPlayer] == && iRPS[iTarget] > 1
|| iRPS[iTarget] == && iRPS[iPlayer] > 1)
{
  
// Action here


</span></span>

Erox902 12-05-2011 12:27

Re: Optimize help
 
The switch statement

hleV 12-05-2011 16:57

Re: Optimize help
 
PHP Code:

switch (iRPS[iPlayer])
{
    case 
1: switch (iRPS[iTarget])
    {
        case 
2:
        {
            
// Action here
        
}
        case 
3:
        {
            
// Action here
        
}
    }
    case 
2: if (iRPS[iTarget] == 1)
    {
        
// Action here
    
}
    case 
3: if (iRPS[iTarget] == 1)
    {
        
// Action here
    
}



jim_yang 12-05-2011 20:57

Re: Optimize help
 
switch(iRPS[iPlayer] * 10 + iRPS[iTarget])
{
case 12:
case 13:
case 21:
case 31:
}
just another option, not much faster than above, I don't know the range of iRPS[] , maybe your should tweak the formula to make the result unique.


All times are GMT -4. The time now is 11:49.

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