Page 1 of 1

multiple else if statements

PostPosted: Thu Aug 11, 2011 5:57 pm
by mal99
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]

Re: multiple else if statements

PostPosted: Thu Aug 11, 2011 6:12 pm
by schnellboot
could you tell us which part of the code doesn't work?

Re: multiple else if statements

PostPosted: Fri Aug 12, 2011 1:34 am
by skydereign
Well as you said not to look for anything in particular, I'm going to say it is no fault of gE that a single condition might not work. gE can use any number of if and else if statements, and it won't have any problems. The only problem that can arise is you creating if statements that can't be done due to complexity. Just because I can't tell what you are actually doing from that code, I'm going to venture the guess that there is a simpler way. I could be wrong, but can't tell without knowing what you are trying to do.

Re: multiple else if statements

PostPosted: Fri Aug 12, 2011 9:16 am
by mal99
Many thanks for the reassurance that multiple if statements such as this can be made to work.

I'll keep looking for the problem. Perhaps there is a conflict between conditions specified in different if statements.

Also, the script is run repeatedly by activation events from 'any actor' - so maybe timing of sending the activations is wrong relative to the many different 'y' positions specified in the if statements .

Mal