multiple else if statements
Posted: Thu Aug 11, 2011 5:57 pm
Would someone with good scripting experience be kind enough to take a quick look at the following. Is it too complex and messy to ever work properly?
Don't bother looking for specific errors or conflicts - I can find those eventually if there is definitely a possibility it might work. Most of it already runs OK, but there always seems to be one statement that doesn't operate.
If there are just too many 'ifs', is there a simpler way to do things?
switch (ktop)
{
case 1:
if (scoreLTOP<1300 && scoreLTOP<scoreL && yvelocity>0.07 && y>top1pos){yvelocity=-0.9;}
else if ( y>top1pos && scoreL>99 && yvelocity>0.07){yvelocity=0.17;}
else if (scoreL<99 && y<30){yvelocity = 0.9;}
else if (y>-100 && scoreL>99){yvelocity=0.07;}
else if (scoreL <99 && y>30){yvelocity = -0.9;}
break;
case 2:
if (y>top1pos && scoreL>99 && yvelocity>0.14){yvelocity=0.34;}
else if ( y>-100 && scoreL>99){yvelocity=0.14;}
else if (scoreL<99 && y<30){yvelocity = 1.8;}
else if (scoreL <99 && y>30){yvelocity = -1.8;}
else if (scoreLTOP<1400 && scoreLTOP<scoreL && yvelocity>0.14 && y>top1pos)
{yvelocity=-1.8;}
break;
}
[/i]
Don't bother looking for specific errors or conflicts - I can find those eventually if there is definitely a possibility it might work. Most of it already runs OK, but there always seems to be one statement that doesn't operate.
If there are just too many 'ifs', is there a simpler way to do things?
switch (ktop)
{
case 1:
if (scoreLTOP<1300 && scoreLTOP<scoreL && yvelocity>0.07 && y>top1pos){yvelocity=-0.9;}
else if ( y>top1pos && scoreL>99 && yvelocity>0.07){yvelocity=0.17;}
else if (scoreL<99 && y<30){yvelocity = 0.9;}
else if (y>-100 && scoreL>99){yvelocity=0.07;}
else if (scoreL <99 && y>30){yvelocity = -0.9;}
break;
case 2:
if (y>top1pos && scoreL>99 && yvelocity>0.14){yvelocity=0.34;}
else if ( y>-100 && scoreL>99){yvelocity=0.14;}
else if (scoreL<99 && y<30){yvelocity = 1.8;}
else if (scoreL <99 && y>30){yvelocity = -1.8;}
else if (scoreLTOP<1400 && scoreLTOP<scoreL && yvelocity>0.14 && y>top1pos)
{yvelocity=-1.8;}
break;
}
[/i]