# hitTest, nested if/then

**URL:** <https://forum.kirupa.com/t/hittest-nested-if-then/163>\
**Category:** flash\
**Created:** [July 8, 2002, 2:04am UTC](https://forum.kirupa.com/t/hittest-nested-if-then/163 "2002-07-08T02:04:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yollo](https://avatars.discourse-cdn.com/v4/letter/y/9fc348/32.png) [@yollo](https://forum.kirupa.com/u/yollo)\
**Post date:** [July 8, 2002, 2:04am UTC](https://forum.kirupa.com/t/hittest-nested-if-then/163/1 "2002-07-08T02:04:26Z")

</div>

Still working on my game. I’m having a little trouble with my collision test. I got everything to work, but I found that if I hit an alien more than once it keeps racking up points and sends the alien explosion animation back to frame one. I tried putting a variable into the alien movie clip to determine if the alien had already been hit or not. Then I put the following commands into my laser shot movie clip:

1. for (i=1; i\<=\_root.numEnemy; i++){
2. 
3. 

```
if (this.hitTest( _root["enemy"+i])){

```

4. 

```
     this.shotSpeed=0;

```

5. 

```
     this.play();

```

6. 

```
      if(_root["enemy"+i].enemyDead="no"){ 

```

7. 

```
             _root.score+=100;

```

8. 

```
          _root["enemy"+i].gotoAndPlay( 13 );

```

9. 

```
             _root["enemy"+i].enemyDead="yes";

```

10. 

```
	      }

```

11. 

```
 }

```

12.}

If I hit an enemy, the laser stops and blows up, like you’d expect (lines 4 and 5). However, the alien doesn’t explode anymore. It’s not getting past the “if” statement on line 6.

I have a line in the alien movie clip for enemyDead=“no”.

---

<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:** [July 8, 2002, 4:20pm UTC](https://forum.kirupa.com/t/hittest-nested-if-then/163/2 "2002-07-08T16:20:44Z")

</div>

Very strange indeed. You say it doesn’t get past the 6th line, when it automatically should. To test the value of enemyDead, you have to put ==

```auto
if(_root["enemy"+i].enemyDead=="no")

```

Otherwise it takes the value 0 and is evaluated as true.

Last thing, don’t use strings like no and yes, but rather 0 and 1 or true and false. Cleaner =)

pom :asian:

---

<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:** [July 9, 2002, 3:04am UTC](https://forum.kirupa.com/t/hittest-nested-if-then/163/3 "2002-07-09T03:04:19Z")

</div>

thanks, that seemed to help, but now I have a different problem. Every once in awhile I’ll get an alien that is invincible. When I hit him I’ll get 100 points, so it’s getting past the if statement. But then it won’t die. Seems to be about one in 10. Here’s the code.

for (i=1; i\<=\_root.numEnemy; i++){

```
 if (this.hitTest( _root["enemy"+i])){
	this.shotSpeed=0;
	this.play();
	if (_root["enemy"+i].enemyDead==false){
	_root.score+=100;
	_root["enemy"+i]. enemyDead=true;
	_root["enemy"+i].gotoAndPlay(13);
	
   }
  
  }
  
}

```

It’s like it won’t get down to the gotoAndPlay (13) line, but I know it must be because I have a sound effect on frame 13 of the alien movie clip and it plays the first time I hit one of these invincible guys.

Maybe I should just leave it be, makes the game more interesting. But it bugs me to not know what’s going on.

Also, off topic, I have a problem with the game slowing down permenently if I hold down the fire button and let loose a lot of bullets. I’m removing the bullet movie clips when they get to a certain point, so I don’t think there’s a problem with too many clips on the stage at one time.
