# Sim error: failed cast on 0

**URL:** <https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905>\
**Category:** Help\
**Created:** [April 30, 2020, 9:12pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905 "2020-04-30T21:12:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napomex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/napomex/32/948_2.png) [@Napomex](https://forum.makecode.com/u/Napomex)\
**Post date:** [April 30, 2020, 9:12pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905/1 "2020-04-30T21:12:59Z")

</div>

Hello everyone, I have a problem with my “big” project at the moment.

see screenshot  
as soon as the opponent fires the projectile the error message appears

 ![Error](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/b06150fb007b7c9e8b2377c400d73e1555b13281.png)

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [April 30, 2020, 9:21pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905/2 "2020-04-30T21:21:41Z")

</div>

Could you share your project? If you haven’t done it before, here’s a GIF that shows how to do it:

 ![2020-03-23 09.17.36](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/b33ee0cc63a7c343c23e4b6dd8665405eae8f852.gif)

Usually that error means that you are calling a function on a sprite before it’s been created. You might want to check your variable dropdowns to make sure you have the right sprite selected and also make sure the sprites has been created.

---

<div class="post-metadata">

**Author:** ![Napomex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/napomex/32/948_2.png) [@Napomex](https://forum.makecode.com/u/Napomex)\
**Post date:** [April 30, 2020, 9:57pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905/3 "2020-04-30T21:57:33Z")

</div>

> **[Microsoft MakeCode Computer Science Education](https://www.microsoft.com/en-us/makecode?rtc=1)**
>
> MakeCode brings computer science to life for all students with fun projects, immediate results, and both block and text editors for learners at different levels.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [April 30, 2020, 10:29pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905/4 "2020-04-30T22:29:46Z")

</div>

The bug is in this overlap event:

 ![Screen Shot 2020-04-30 at 3.28.28 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/3eff1bfc142f861e6ab09d0a3d138316c3d0d1d3.png)

The variable “projectile” was never assigned to, so it’s causing the error at runtime. I think you want to use the “sprite” local variable just like you are with “otherSprite”

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [April 30, 2020, 10:32pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905/5 "2020-04-30T22:32:51Z")

</div>

The way I figured this out, was by using the debugger! If you go to [arcade.makecode.com/beta](http://arcade.makecode.com/beta) we’ve added exceptions to the debugger.

In other words, if you hit a simulator error while your program is running, it will pause the program and highlight the block that is causing the issue like this:

 ![Screen Shot 2020-04-30 at 3.30.59 PM](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/2cd160c1645545651f8bc4d7cae1d505eae59be0.png)

To activate the debugger, hit the bug button underneath the simulator

---

<div class="post-metadata">

**Author:** ![Napomex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/napomex/32/948_2.png) [@Napomex](https://forum.makecode.com/u/Napomex)\
**Post date:** [May 1, 2020, 10:04am UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-0/1905/6 "2020-05-01T10:04:06Z")

</div>

THX this is a great feature 😃
