Program error: sim error: failed cast on null

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

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

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

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

3 Likes