# Projectile Not Destroying

**URL:** <https://forum.makecode.com/t/projectile-not-destroying/3282>\
**Category:** Help\
**Created:** [August 31, 2020, 1:12pm UTC](https://forum.makecode.com/t/projectile-not-destroying/3282 "2020-08-31T13:12:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![techahoynyc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/techahoynyc/32/1023_2.png) [@techahoynyc](https://forum.makecode.com/u/techahoynyc)\
**Post date:** [August 31, 2020, 1:12pm UTC](https://forum.makecode.com/t/projectile-not-destroying/3282/1 "2020-08-31T13:12:24Z")

</div>

Hey all I have another weird bug plaguing my game. I am trying to destroy a projectile when it overlaps the enemy and then subtract 1 from the enemy’s statusbar. I have used this code countless times before, but for some reason in this game my projectile isn’t consistently being destroyed and sometimes causing 1-5 damage. 😡

> **[a-maze-ing-d10-class](https://arcade.makecode.com/78445-66022-93506-90520)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

As a sanity check, I created a test game using the same images and coding logic and of course it is working as expected:

> **[a-maze-ing projectile test](https://arcade.makecode.com/66519-56323-22605-39573)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Any ideas? Are my animations causing the issue? Duplicative ongame update blocks? I’m really not sure where to look from here - I ran the game in debug mode and saw the destroy block run and watched the projectile survive for several more overlaps before it finally vanished.

I appreciate any ideas for possible fixes.

---

<div class="post-metadata">

**Author:** ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)\
**Post date:** [August 31, 2020, 1:50pm UTC](https://forum.makecode.com/t/projectile-not-destroying/3282/2 "2020-08-31T13:50:18Z")

</div>

Problem is not at projectile overlapping enemy handling code, but firing projectile.

Note that these 2 ways of firing projectile is different:

In the test field,

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/909085725c35371333c9f793fddcf2ae982b2f44.png)  
in the project,  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/b9d62ede07ba0b388690dd6dddbbfdb45a0a77b8.png)

The latter fires multiple projectiles because on game update runs every ‘game tick’ or something like that, while on A button press run only once when each time a button is change from release to press.

Adding a ‘add 1 score after firing projectile’ will make it clear.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c1e31c2d97bb043059ad6d5698cacda7b13233f8.png)

I can see that A button press behaves differently in menu / in-game, my usual way would be separating the concern by state variable and function, something like:

```
onAButtonPressed() {
    if (mode == Menu) {
        doMenuSelect()
    } else if (mode == InGame) {
        handleFiringLogic()
    }
}
```

---

<div class="post-metadata">

**Author:** ![techahoynyc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/techahoynyc/32/1023_2.png) [@techahoynyc](https://forum.makecode.com/u/techahoynyc)\
**Post date:** [August 31, 2020, 2:15pm UTC](https://forum.makecode.com/t/projectile-not-destroying/3282/3 "2020-08-31T14:15:59Z")

</div>

Ah - that makes sense @felixtsu and I agree with the change in logic using state variable. I’ll make the changes. Thanks!

---

<div class="post-metadata">

**Author:** ![techahoynyc](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/techahoynyc/32/1023_2.png) [@techahoynyc](https://forum.makecode.com/u/techahoynyc)\
**Post date:** [August 31, 2020, 2:33pm UTC](https://forum.makecode.com/t/projectile-not-destroying/3282/4 "2020-08-31T14:33:47Z")

</div>

Success! Thanks again for the help.

> **[a-maze-ing-d10-class](https://arcade.makecode.com/18537-63191-32882-93991)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.
