I’m sure this is a fairly simple question but this is my first time playing around with MakeCode and was wondering if someone felt like suggesting some fixes.
I’m trying to simply have my character kill the enemy with my projectile when hitting A. It seems like there’s possibly some sort of implicit order that MakeCode follows that I’m not aware of because the projectile killed enemies previously but then I moved around code and am not sure how I had things set up before. There were a few such instances, such as the game would end when I would have it set up to just lose a life until it hit 0 lives (then game over). I’ve attached the code and included a picture below. I removed that bit because it wasnt working just to try to debug other things.
Thanks for the help!
Ah, it looks like you’re using the global “enemySprite” variable in your events. When coding overlap events, you want to drag out the local variable from the event like so:
The reason this was causing a bug was that every time a new enemy is created, the enemySprite variable is being updated to point to the new enemy. So every time you tried to destroy the enemy it would destroy whatever the most recently created one was instead of the one that was actually in the overlap event.
Ah okay! That makes sense, thank you for the help.
I updated the blocks but neither the lives nor the projectiles are working properly. I attached the updated blocks/code here.
They seem to be working for me…what is it supposed to be doing that it’s not?
Hmm, that’s interesting! Mine is still not killing the enemy when I hit it with a projectile and the lives counter isn’t working (I lose a life but the game ends instead of just counting down until I have 0 lives).
Try opening the PNG in a private window. See if it works for you when you’re on a different browser.
hello and welcome to the forums @rng
That fixed it! Thank you!!