My student keeps getting Sim error: failed cast on null. We can’t seem to figure out why. https://makecode.com/_LVKM6fR641qc
What I’ve noticed is that this game sets the trash positions before it actually declares the trash sprites. You could fix this problem by taking out the ‘if any button pressed’ in the ‘on start’ event. I hope this helps!
In the code there is a forever loop that changes " trash right" and “trash left”'s position.
but that actually happens before “trash right” and “trash left” exist.
If I told you, “Move the cup there”, and there wasn’t a cup at all, you would be unsure what to do. Its basically the same for a computer.
Thanks so much. I forgot to mention the student’s one request…to start the game when any button is pressed. Any suggestions are appreciated.
Alright, I fixed the problem (I think)! I just added a true/false variable that asks whether or not the game is started. Here’s the link to the updated game:
I hope this helps!
you can also take away the if block to start because the game can’t comprehend it and the trash can’t be placed at 150 because the tilemap isn’t big enough.
- In my experience this happens when you modify a sprite before you declare it.
You need to use the Create Sprite block (1st block under sprites) - or the Projectile block first.
- Then you can set position, destroy, etc.
Generally - the error is in OnStart blocks. But if you set a projectile to spawn when you hit a button, or if you have a timer block that spawns a projectile in a certain timeframe - then you have a loopForever block that does something to the projectile you can also run into a problem.
Awesome. Thank you very much!!!
Thanks so much!
Thanks so much!