# Program error: sim error: failed cast on null

**URL:** <https://forum.makecode.com/t/program-error-sim-error-failed-cast-on-null/28831>\
**Category:** Help\
**Created:** [May 20, 2024, 1:25am UTC](https://forum.makecode.com/t/program-error-sim-error-failed-cast-on-null/28831 "2024-05-20T01:25:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [May 20, 2024, 3:16am UTC](https://forum.makecode.com/t/program-error-sim-error-failed-cast-on-null/28831/2 "2024-05-20T03:16:15Z")

</div>

Hi, @ruprion !

Whenever I get an error like this, especially when the error is _repeatable_ (meaning, I know when the error will happen), then I often use the debugger to show me where the problem is.

To turn on the debugger, select the **debug** button below the game controls. Screenshot below.

![Debug button highlighted beneath the MakeCode Arcade simulator](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/0/0b3fafd8735511a1439f2f10f10a8c56376852f3.png)

When I run the debugger on your program and select the **A** button after the attract screen, the debugger highlights this block inside of your **on A button pressed** handler:

![Block with error highlighted in debugger](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/5/537fbfabb75b51b9a5a825743e9c4243de68caab.png)

I’m guessing that the variable `mySprite` has not yet been defined when you exit the attract screen. You may need to create a new variable (perhaps something like `isGameStarted`) that you set to `true` once the game actually begins, and then check that variable within your **A** button handler:

![Original on A button pressed handler now surrounded by an block](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/9/9e789fce54ed9e2f348e2fbb18e408070a143e39.png)

Let us know if you’re still stuck! Good luck on your project!

---

_[View the full topic](https://forum.makecode.com/t/program-error-sim-error-failed-cast-on-null/28831)._
