# If statements (novice)

**URL:** <https://forum.kirupa.com/t/if-statements-novice/61656>\
**Category:** Uncategorized\
**Created:** [August 20, 2004, 10:52am UTC](https://forum.kirupa.com/t/if-statements-novice/61656 "2004-08-20T10:52:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sci](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@sci](https://forum.kirupa.com/u/sci)\
**Post date:** [August 20, 2004, 10:52am UTC](https://forum.kirupa.com/t/if-statements-novice/61656/1 "2004-08-20T10:52:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 11:18am UTC](https://forum.kirupa.com/t/if-statements-novice/61656/2 "2004-08-20T11:18:33Z")

</div>

Put this after every \*\*IF \*\*statement

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 11:37am UTC](https://forum.kirupa.com/t/if-statements-novice/61656/3 "2004-08-20T11:37:10Z")

</div>

like this:

on (release) {  
if (\_root.case\_01.hitTest(\_root.input\_01)){  
{  
gotoAndPlay(5);  
}  
else{ gotoAndPlay(3)}  
}  
}

it says this code contains errors

> [@interfector](#):
>
> Put this after every \*\*IF \*\*statement
> 
> ```auto
>  
> { 
> gotoAndPlay(5);
> }
> else{ gotoAndPlay(3)}
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 3:58pm UTC](https://forum.kirupa.com/t/if-statements-novice/61656/4 "2004-08-20T15:58:27Z")

</div>

Like this:

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 20, 2004, 11:08pm UTC](https://forum.kirupa.com/t/if-statements-novice/61656/5 "2004-08-20T23:08:41Z")

</div>

maybe this will help you?

[Prophets mini tute on IF statements 😉](http://www.kirupaforum.com/forums/showthread.php?t=60750)

Prophet.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 21, 2004, 1:05am UTC](https://forum.kirupa.com/t/if-statements-novice/61656/6 "2004-08-21T01:05:47Z")

</div>

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

```php
 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:

```php

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 26, 2004, 11:41am UTC](https://forum.kirupa.com/t/if-statements-novice/61656/7 "2004-08-26T11:41:16Z")

</div>

thanks for your help deQue.

I tweaked your code a bit but my movie still doesn’t seem to be functioning correctly. For example, if you put all the correct movie clips (case\_06 etc) into only one of the two boxes and press the submit button you still pass the test. Here’s the code I’m now using on the submit button:

on(release){  
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);  
}

}

any ideas much appreciated!
