# Using the x position of a sprite to change score

**URL:** <https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957>\
**Category:** Help\
**Created:** [September 9, 2021, 3:07pm UTC](https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957 "2021-09-09T15:07:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![breakingboredomloops](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@breakingboredomloops](https://forum.makecode.com/u/breakingboredomloops)\
**Post date:** [September 9, 2021, 3:07pm UTC](https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957/1 "2021-09-09T15:07:55Z")

</div>

Hi!  
In this game, a plane shoot bullets to destroy incoming ‘lasers’.  
When a laser is hit the score increments up by 1.  
I cannot figure out how to get the score to decrement by one when the laser gets past the plane.  
Please help. I experimented with tile maps, grid data etc and then just went back to a background image and tried using the x position data, however, it doesn’t run my if statement when laser x \< 20.

> **[dodge - version 5.1](https://arcade.makecode.com/53428-83219-99746-82655)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [September 10, 2021, 12:44am UTC](https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957/2 "2021-09-10T00:44:32Z")

</div>

Great game!

Because you’re creating them as projectiles, the bullet sprites are destroyed when they leave the screen. So, this block might be helpful:

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

The conditional can test whether `sprite` has left the screen. (_Hint_: It won’t be when `x < 20`. What is the `x` coordinate of the bullet when it reaches the right side of the screen?)

Also, do you want the player’s score to go negative? If not, then you can create a _compound conditional_ (a “test” with an _and_ or _or_ in it), only deducting a point if the score is positive.

I’ve hidden my code behind a spoiler so that you can try it yourself. If you get stuck, then just click on the image to reveal it.

If you want the score to go negative, then you only need the first part of the conditional.

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

---

<div class="post-metadata">

**Author:** ![breakingboredomloops](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@breakingboredomloops](https://forum.makecode.com/u/breakingboredomloops)\
**Post date:** [September 13, 2021, 5:09pm UTC](https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957/3 "2021-09-13T17:09:37Z")

</div>

Thanks for the help! It definitely aided my brain and I rethought the problem and found another two solutions that seemed to work. See below. I like your solution, but don’t understand why the x position is \> or equal to screen width. The laser is coming from the right of the screen when the x position should equal the screen width. If the player doesn’t hit and destroy the laser then the x position is \<0 as it passes to the left of the screen. Maybe the answer is that x is always between 0-screen width and never = \<0? The player position is around x = 23 and that’s why I used x\<20 (as in the laser got behind the player).

solution 1: [https://makecode.com/\_A7EMo5bXg0aH](https://makecode.com/_A7EMo5bXg0aH)

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

---

<div class="post-metadata">

**Author:** ![breakingboredomloops](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@breakingboredomloops](https://forum.makecode.com/u/breakingboredomloops)\
**Post date:** [September 13, 2021, 5:09pm UTC](https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957/4 "2021-09-13T17:09:51Z")

</div>

solution 2: less sophisticated. Just +2 and -1 from the two different on sprite destroy blocks so that the overall effect on the code is +1 when hit or -1 when not hit.

> **[dodge - version 5.2](https://arcade.makecode.com/41906-05247-99367-09767)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

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

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [September 13, 2021, 6:37pm UTC](https://forum.makecode.com/t/using-the-x-position-of-a-sprite-to-change-score/9957/5 "2021-09-13T18:37:20Z")

</div>

I misread your question - I thought you wanted the score to decrease when a _bullet_ left the screen. You were talking about the lasers, though.

You have the right idea, for sure. This is how I did it:

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

You also need to change the code in your `on game update` loop where you create the lasers, and change the auto-destroy flag to `ON`.
