# Sim error failed cast on null

**URL:** <https://forum.makecode.com/t/sim-error-failed-cast-on-null/32586>\
**Category:** Help\
**Created:** [December 18, 2024, 11:06pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/32586 "2024-12-18T23:06:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![I\_No](https://avatars.discourse-cdn.com/v4/letter/i/e95f7d/32.png) [@I\_No](https://forum.makecode.com/u/I_No)\
**Post date:** [December 18, 2024, 11:06pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/32586/1 "2024-12-18T23:06:59Z")

</div>

I get the sim error on the code below which  
I am doing for class, I know very little about makecode but nether me nor my teacher can figure out why the code is erroring

P.S Josh it’s be reginn I didn’t steal my code from the internet

> **[Knights Vs Nature](https://arcade.makecode.com/S63686-12512-29047-60903)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

[[https://arcade.makecode.com/S63686-12512-29047-60903](https://arcade.makecode.com/S63686-12512-29047-60903)]

---

<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:** [December 19, 2024, 3:52am UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/32586/2 "2024-12-19T03:52:38Z")

</div>

so, you’re changing rock to be rock type before actually creating the rock, so just put the “set rock to rock type” block thing after the block where you create the rock (same for sword).

---

<div class="post-metadata">

**Author:** ![upperalpaca2407](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/upperalpaca2407/32/35682_2.png) [@upperalpaca2407](https://forum.makecode.com/u/upperalpaca2407)\
**Post date:** [December 19, 2024, 12:09pm UTC](https://forum.makecode.com/t/sim-error-failed-cast-on-null/32586/3 "2024-12-19T12:09:34Z")

</div>

yes mega0star01s right  
you changing the rock type before creating the rock
