# If statements (novice)

**URL:** <https://forum.kirupa.com/t/if-statements-novice/120066>\
**Category:** Uncategorized\
**Created:** [August 20, 2004, 10:52am UTC](https://forum.kirupa.com/t/if-statements-novice/120066 "2004-08-20T10:52:00Z")\
**Posts on this page:** 6\
**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/120066/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:** ![interfector](https://avatars.discourse-cdn.com/v4/letter/i/898d66/32.png) [@interfector](https://forum.kirupa.com/u/interfector)\
**Post date:** [August 20, 2004, 11:18am UTC](https://forum.kirupa.com/t/if-statements-novice/120066/2 "2004-08-20T11:18:33Z")

</div>

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

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

```

---

<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, 11:37am UTC](https://forum.kirupa.com/t/if-statements-novice/120066/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:** ![interfector](https://avatars.discourse-cdn.com/v4/letter/i/898d66/32.png) [@interfector](https://forum.kirupa.com/u/interfector)\
**Post date:** [August 20, 2004, 3:58pm UTC](https://forum.kirupa.com/t/if-statements-novice/120066/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:** ![Prophet](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@Prophet](https://forum.kirupa.com/u/Prophet)\
**Post date:** [August 20, 2004, 11:08pm UTC](https://forum.kirupa.com/t/if-statements-novice/120066/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:** ![deQue](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@deQue](https://forum.kirupa.com/u/deQue)\
**Post date:** [August 21, 2004, 1:05am UTC](https://forum.kirupa.com/t/if-statements-novice/120066/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…
