# Why doesn't my code work?

**URL:** <https://forum.makecode.com/t/why-doesnt-my-code-work/3432>\
**Category:** Help\
**Created:** [September 11, 2020, 10:41pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432 "2020-09-11T22:41:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [September 11, 2020, 10:41pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/1 "2020-09-11T22:41:14Z")

</div>

> **[Traffic Jam](https://arcade.makecode.com/00231-08484-61380-08485)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [September 11, 2020, 11:37pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/2 "2020-09-11T23:37:27Z")

</div>

![Screenshot_20200911-193629](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/2/2176cc8a2d75c37f6efc770a2acf8c5c7835ee31.png)

`value` is a location, not a tile.

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [September 12, 2020, 3:46pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/3 "2020-09-12T15:46:19Z")

</div>

How can I fix this?

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [September 12, 2020, 4:08pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/4 "2020-09-12T16:08:23Z")

</div>

I don’t know how to fix it. ☹

---

<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 12, 2020, 6:02pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/5 "2020-09-12T18:02:56Z")

</div>

Hi, @GameGod !

It looks like you’re trying to figure out which tile a sprite is on. I don’t think there’s an easy way to do this with blocks. I think you need to use some math to figure it out.

You can find the coordinates of the sprite. Because we know that tiles are 16 pixels wide and 16 pixels tall, we can figure out which tile the sprite is on, too. Once you know which tile the sprite is on, you can test for which kind of tile it is. I used a `sprite say` statement so that I could see how the values changed as I moved the car around.

 ![arcade-screenshot (1)](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9e6a3ad13a38dd6ca5d38c267a0424be52e47bc9.png)

If you’re still stuck, or if I misunderstood what you were trying to do, let us know. Good luck!

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [September 12, 2020, 9:18pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/6 "2020-09-12T21:18:51Z")

</div>

This is epic! Thanks for the help, @AlexK and @UnsignedArduino !

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [September 12, 2020, 9:38pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/7 "2020-09-12T21:38:32Z")

</div>

1. I just have a few more questions. How can I do this for sprites with dimensions of `16x32` or `16x48`? I tried adding another if statement at the end and changing the values in it, but it seems to not work.

2. How can I turn off a tile’s wall property if there is no sprite on it? Basically, I want walls on every sprite so the other sprites can’t pass. Here is my code so far. Thanks in advance.

> **[Traffic Jam](https://arcade.makecode.com/18044-59100-08831-69735)**
>
> 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 13, 2020, 10:26pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/8 "2020-09-13T22:26:09Z")

</div>

First, I must say that I _love_ this idea for the Game Jam!

So, I figured out how to turn the walls on and off. I only worked on `Limo H3` just to work out some thoughts.

> **[Traffic Jam](https://arcade.makecode.com/55002-47253-83596-48907)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Then, I realized there was a problem. 😃

If you try to turn the walls on in the double-loop, then `Limo H3` _also_ can’t move. Because it’s hitting a wall. 🙂

I think, instead of trying to turn walls on and off, you’re better bet instead will be to handle when two cars overlap. When two cars overlap, figure out which car is moving and then stop it from moving.

Good luck!

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [September 13, 2020, 11:59pm UTC](https://forum.makecode.com/t/why-doesnt-my-code-work/3432/9 "2020-09-13T23:59:06Z")

</div>

Ok! I actually am working on a new way to do it using `for loops` and `on button pressed`.

.
