# I have a problem with fail to cast on null

**URL:** <https://forum.makecode.com/t/i-have-a-problem-with-fail-to-cast-on-null/23462>\
**Category:** Help\
**Tags:** game\
**Created:** [October 17, 2023, 9:30pm UTC](https://forum.makecode.com/t/i-have-a-problem-with-fail-to-cast-on-null/23462 "2023-10-17T21:30:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kknuser](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kknuser](https://forum.makecode.com/u/kknuser)\
**Post date:** [October 17, 2023, 9:30pm UTC](https://forum.makecode.com/t/i-have-a-problem-with-fail-to-cast-on-null/23462/1 "2023-10-17T21:30:54Z")

</div>

I am having troubles with failed to cast on null, I dont know where to begin I am kinda new and my code is kinda big.

> **[dungeon game](https://arcade.makecode.com/S45795-25719-88949-25695)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Link to the project

---

<div class="post-metadata">

**Author:** ![Vegz78](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/vegz78/32/1201_2.png) [@Vegz78](https://forum.makecode.com/u/Vegz78)\
**Post date:** [October 18, 2023, 4:36pm UTC](https://forum.makecode.com/t/i-have-a-problem-with-fail-to-cast-on-null/23462/2 "2023-10-18T16:36:03Z")

</div>

Welcome @kknuser and nice game!

Running the game in debug mode indicates that the sprite _mirror\_master_ might be referenced inside the _forever loop_ before it is created.

 ![mirror_master](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/498ddaf6ae38b06d887135608f23bef19da696e4.png)

---

<div class="post-metadata">

**Author:** ![British-Eddie](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/british-eddie/32/11201_2.png) [@British-Eddie](https://forum.makecode.com/u/British-Eddie)\
**Post date:** [October 18, 2023, 4:36pm UTC](https://forum.makecode.com/t/i-have-a-problem-with-fail-to-cast-on-null/23462/3 "2023-10-18T16:36:14Z")

</div>

It looms like the reason your getting the error is because your trying to reference the sprite “mirror\_master” in the forever loop before it’s created:

 ![Screenshot 2023-10-18 at 6.00.20 pm](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/c/c585026fc11522fee2e6bdbf70df7b13d90e2137.png)  
To avoid the null error, I’d suggest either:  
creating the mirror\_master sprite at the start of the game,  
make sure if mirror\_master has been created before the if statements, which would look like this:  
 ![Screenshot 2023-10-18 at 6.10.20 pm](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/46450ec36b2082c8196f406879348b7a482ed325.png)  
or preferably use the “Move (Sprite) With Buttons” to move mirror\_master as it automatically checks if the sprite has been created.  
Hope that helps!
