# Need help with: Compare sprite from an array of sprites and if match, do something

**URL:** <https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511>\
**Category:** Help\
**Created:** [September 22, 2022, 7:23pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511 "2022-09-22T19:23:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![stoian](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@stoian](https://forum.makecode.com/u/stoian)\
**Post date:** [September 22, 2022, 7:23pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/1 "2022-09-22T19:23:29Z")

</div>

Hello everyone,

I am new to MS Makecode arcade and am trying to figure out the following scenario.  
I have an array of two sprites which are randomly being created at random positions on X axis. All good so far.  
Now, I want to be able to shoot a projectile from one of the sprites. For that I use if then logic, but it just doesn’t work. See screenhots below. Can you help me figure our where do I make a mistake?  
If I do not do a comparison, both sprites are correctly shooting projectiles.

Thank you!

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e4bad0d4fe98a7b9d85e4c9f8f5c2070bb2eb878.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/86db22570c2bf31102c4c0467eaa65c95a99fb07.png)

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [September 22, 2022, 8:18pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/2 "2022-09-22T20:18:16Z")

</div>

You should use the image block in advance or in the sprites section and there is 3 different blocks will help you with that  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c21feba2382e385e2dae3769f9b35ffdd421cb0f.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9d7a4e100537f17d8597cd9682a810d055931a43.png)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/490495d4ef24be0c2f69e481fcf4da578c96a76e.png)  
These are the blocks

---

<div class="post-metadata">

**Author:** ![stoian](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@stoian](https://forum.makecode.com/u/stoian)\
**Post date:** [September 22, 2022, 9:48pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/3 "2022-09-22T21:48:46Z")

</div>

You are my star! thank you! it worked like a charm.

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [September 22, 2022, 10:13pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/4 "2022-09-22T22:13:39Z")

</div>

No problem

---

<div class="post-metadata">

**Author:** ![stoian](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@stoian](https://forum.makecode.com/u/stoian)\
**Post date:** [September 22, 2022, 10:13pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/5 "2022-09-22T22:13:52Z")

</div>

I am sorry for the double post, but I cannot edit the initial one. Here is a screenshot of the working portion:

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

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [September 22, 2022, 10:43pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/6 "2022-09-22T22:43:44Z")

</div>

no i meant you can only use one of the blocks not 2 of the block the same time

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [September 26, 2022, 4:49pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/7 "2022-09-26T16:49:36Z")

</div>

These 2 blocks you can use at the same time  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/92ea53a43c64f10b65a976bd67df23663625b31e.png)  
but you need a boolean

**“mySprite.image = image”**

or the other one  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/7dd4511cfcb9d09cced3fc528f8abc2ad5808ad4.png)  
That’s you have to use the 1 block just change the variable into the sprite you need like this

**“myEnemy is equal to image (image)”**

Ye like that I’m sorry if I made it confusing

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [September 26, 2022, 6:14pm UTC](https://forum.makecode.com/t/need-help-with-compare-sprite-from-an-array-of-sprites-and-if-match-do-something/15511/8 "2022-09-26T18:14:17Z")

</div>

sory for the late reply i was on somewere
