If statements (novice)

Hi

I’m constructing a game for college and I’ve run into a problem. Forgive me if the solution is blatently obvious. Anyway… I’ve created a drag and drop game,

I have 9 instances called “case_01”, “case_02” etc. The user must place them into one of two boxes (called “input_01” and “process_01”). I’ve then created an incorrect message on frame 3 and a correct mesage on frame 5.

I’ve placed the following code on the submit button with the correct answers:

on (release) {
if (_root.case_01.hitTest(_root.input_01))
if (_root.case_02.hitTest(_root.input_01))
if (_root.case_03.hitTest(_root.input_01))
if (_root.case_04.hitTest(_root.input_01))
if (_root.case_05.hitTest(_root.input_01))
if (_root.case_06.hitTest(_root.process_01))
if (_root.case_07.hitTest(_root.process_01))
if (_root.case_08.hitTest(_root.process_01))
if (_root.case_09.hitTest(_root.process_01)){

gotoAndPlay(5);
}
else{ gotoAndPlay(3)}
}

but this isn’t working correctly. Must each if have an else? I’m a complete novice at this actionscripting so any help would be much appreciated.

Put this after every **IF **statement

 
{ 
gotoAndPlay(5);
	}
	 else{ gotoAndPlay(3)}
	}
}

like this:

on (release) {
if (_root.case_01.hitTest(_root.input_01)){
{
gotoAndPlay(5);
}
else{ gotoAndPlay(3)}
}
}

it says this code contains errors

Like this:


on (release) 
{
if (_root.case_01.hitTest(_root.input_01))
	 {
	 gotoAndPlay(5);
	 }
	 else
	 {
	 gotoAndPlay(3)
	 }
 
}
 

maybe this will help you?

Prophets mini tute on IF statements :wink:

Prophet.

Ok, for this there are two options:
First option is:

 on (release) { 
	if (_root.case_01.hitTest(_root.input_01)) {
		if (_root.case_02.hitTest(_root.input_01)) {
			if (_root.case_03.hitTest(_root.input_01)) {
				if (_root.case_04.hitTest(_root.input_01)) {
					if (_root.case_05.hitTest(_root.input_01)) {
						if (_root.case_06.hitTest(_root.process_01)) {
							if (_root.case_07.hitTest(_root.process_01)) {
								if (_root.case_08.hitTest(_root.process_01)) {
									if (_root.case_09.hitTest(_root.process_01)) {
									 gotoAndPlay(5);
									}
										else{ gotoAndPlay(3)}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

The second option (which is the proper coding for this) is:


for (var i=1; i<=9; i++) {
	if (i<=5) {
		if (_root["case_0"+i]hitTest(_root.input_01)) hitsOK = true;
		else hitsOK = false;
	} else { 
		if (_root["case_0"+i]hitTest(_root.process_01)) hitsOK = true;
		else hitsOK = false;
	}
}
if (hitsOK) gotoAndPlay(5);
else gotoAndPlay(3);

Let me know if you have any questions…