multiple else if statements

Non-platform specific questions.

multiple else if statements

Postby mal99 » 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]
mal99
 
Posts: 10
Joined: Tue May 31, 2011 11:47 pm
Score: 0 Give a positive score

Re: multiple else if statements

Postby schnellboot » Thu Aug 11, 2011 6:12 pm

could you tell us which part of the code doesn't work?
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: multiple else if statements

Postby skydereign » Fri Aug 12, 2011 1:34 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: multiple else if statements

Postby mal99 » Fri Aug 12, 2011 9:16 am

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
mal99
 
Posts: 10
Joined: Tue May 31, 2011 11:47 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest