Hello,I have a problem with my game and I would like to see if anyone can help me.
I am doing this class project and until a moment ago everything was correct, until at a certain point I got the error “sim error: failed cast on null” and it did not allow me to play what I was developing.
Also when catching the box, which is supposed to have 2 points, one life was subtracted and the sound of the bomb was played, which I don’t know why it happens. Normally the error appears when the player interacts with the points box.
This is the link of the project in question: https://arcade.makecode.com/S68959-27751-89365-08747
Thank you in advance for your help
Welcome to the forum!
I see a few problems here. First, let’s look at where you’re creating the projectiles:
The “projectile [image] from [mysprite]” block will always create a Sprite with the kind Projectile. That means both the bomb and the box will have the same kind.
If we look at your overlap code for the box:
You are referencing a kind called “proyectile2” which is never actually used in your program.
To make this work, you probably want to set the kind of the box projectile after you create it. Like so:
Another issue in your program is that you are using global variables inside your overlap events. This is a really common mistake I see people make.
For example, in the overlaps event for the bomb, you are using the “projectile” variable:
You probably don’t want to do that because the projectile variable might not be pointing to the bomb that you’re overlapping with when this code runs. Instead, you can drag out the “otherSprite” variable from the top of the event and use that in its place.
This is also true for your box overlap code, which has the same issue.
I understand, although I have a doubt. How could I make the box continue to be a projectile but not be affected in the same way as the bomb?
I think it stays with all the attributes of a projectile - velocity and gets destroyed when it leaves the screen - even after you change the type. Just spawn it in as a projectile and then use the “Set (myProjectile) kind to (player)” block right after it gets created. “Player” can be whatever you want. I would make my own kind or use “Food” or something idk