# Pls tell me what is wrong whith this bit of code it ceeps saying sim error failed cast on null

**URL:** <https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774>\
**Category:** Help\
**Created:** [July 21, 2024, 7:39pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774 "2024-07-21T19:39:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frastheman](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Frastheman](https://forum.makecode.com/u/Frastheman)\
**Post date:** [July 21, 2024, 7:39pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/1 "2024-07-21T19:39:49Z")

</div>

![VideoCapture_20240721-155444](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/c/f/cf33957a8d5b13e85781666b28adc84f182144e3.jpeg)

---

<div class="post-metadata">

**Author:** ![Mega0star01](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mega0star01/32/14784_2.png) [@Mega0star01](https://forum.makecode.com/u/Mega0star01)\
**Post date:** [July 21, 2024, 10:15pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/2 "2024-07-21T22:15:31Z")

</div>

that has nothing wrong, please send the link.

---

<div class="post-metadata">

**Author:** ![Frastheman](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Frastheman](https://forum.makecode.com/u/Frastheman)\
**Post date:** [July 22, 2024, 4:24am UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/3 "2024-07-22T04:24:15Z")

</div>

> **[ninja run - good](https://arcade.makecode.com/S24026-27832-78545-48347)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Frastheman](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Frastheman](https://forum.makecode.com/u/Frastheman)\
**Post date:** [July 22, 2024, 4:28am UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/4 "2024-07-22T04:28:02Z")

</div>

And it is only that start part

---

<div class="post-metadata">

**Author:** ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)\
**Post date:** [July 22, 2024, 3:09pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/5 "2024-07-22T15:09:57Z")

</div>

You haven’t defined a sprite just create one on start

---

<div class="post-metadata">

**Author:** ![neintoes](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/neintoes/32/8315_2.png) [@neintoes](https://forum.makecode.com/u/neintoes)\
**Post date:** [July 22, 2024, 3:13pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/6 "2024-07-22T15:13:54Z")

</div>

In a lot of your code you’re trying to tun sprite functions on ' **mySprite** but you’ve removed the code that sets the var **mySprite** as a sprite from your ‘on start’ block.

As it’s not being created as a sprite you cannot call sprite functions on that var.

Fix this by dragging this big ole’ chunk of code back into your ‘on start’ and it’ll start working again:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/7/7/773b1742d82bdfa025d80809238ddc3270e955d4.png)

---

<div class="post-metadata">

**Author:** ![Table](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/table/32/16503_2.png) [@Table](https://forum.makecode.com/u/Table)\
**Post date:** [July 22, 2024, 3:14pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/7 "2024-07-22T15:14:31Z")

</div>

There’s a forever function in there with an if statement containing variable “mySprite”, but the sprite wasn’t made yet in the start function/levle function, so the game freaks out

---

<div class="post-metadata">

**Author:** ![Mega0star01](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mega0star01/32/14784_2.png) [@Mega0star01](https://forum.makecode.com/u/Mega0star01)\
**Post date:** [July 22, 2024, 5:53pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/8 "2024-07-22T17:53:58Z")

</div>

well, that’s the problem you had @Frastheman

---

<div class="post-metadata">

**Author:** ![Frastheman](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@Frastheman](https://forum.makecode.com/u/Frastheman)\
**Post date:** [July 22, 2024, 9:20pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/9 "2024-07-22T21:20:35Z")

</div>

Thank you all very much

---

<div class="post-metadata">

**Author:** ![BloonsFan3](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bloonsfan3/32/16226_2.png) [@BloonsFan3](https://forum.makecode.com/u/BloonsFan3)\
**Post date:** [July 23, 2024, 3:52pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/10 "2024-07-23T15:52:43Z")

</div>

fixed it!

> **[ninja run - FIXED](https://arcade.makecode.com/S06209-80488-65274-81986)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![User7](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/user7/32/16035_2.png) [@User7](https://forum.makecode.com/u/User7)\
**Post date:** [July 23, 2024, 3:56pm UTC](https://forum.makecode.com/t/pls-tell-me-what-is-wrong-whith-this-bit-of-code-it-ceeps-saying-sim-error-failed-cast-on-null/29774/11 "2024-07-23T15:56:27Z")

</div>

Also here is a pfp!  
 ![Screenshot 2024-07-20 2.55.24 AM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/3X/3/9/3944c4aef59ab482d7a7465718951eab520793f1.png)
