Help with health bug!

Hello!

I’m new to coding so I decided I would try out Microsoft MakeCode and it’s really fun. I’m making a platformer game with 2+ levels but am currently having issues with my health item. It’s a heart that’s supposed to give you one extra heart (you can’t get more than three). It works perfectly on level one but on level two it gets all weird and doesn’t disappear and keeps giving the user hearts nonstop.

Do any of you guys know what the problem is? Thank you! And tell me if you see any other bugs, problems, or advice you could give me :slight_smile:

https://makecode.com/_EeVVfcMFyFoa

image
Here’s something I tweaked a bit. Do this with your levels so then your levels and code would work and it’s smaller than what you did before.
image
And instead of this, you can change the level number and then go right to the level changing function.
image
This is what I tweaked it to be like
image
If you want to fix this, you might want to get the whole if statements out of the way and not have them to have a limit of lives.
Never mind that didn’t work. Maybe since all the last part of level two is a platforming skills part, you don’t necessarily need lives because if you fall, you game over anyway.

I say, remove the hearts from level two and see what that does for you.


Here’s the game.
I removed the hearts from level two.

Hi, @fatasianpanda. Welcome!

Take a look at your collision event handler:

image

Instead of using your variable, heart3, use the local variable instead, otherSprite. I’ve also simplified your code a little bit. (I know you were trying to debug.)

image

See if that fixes your error with the hearts in level 2. If it doesn’t, or if you’re having other difficulties, just let us know!

P. S. Nice work so far on the game!

Thank you so much for your help! It got fixed :smiley:

1 Like

Do you know if theres anyway to add a system where you can select which level you want to play? Or for the player to reset in the current level they’re in rather than just restart the whole game? I’ve tried to make a function where it’ll ask if you want to continue if you die and it’ll take you back to the beginning of the level, but It wouldn’t really work. Thanks for your time!

You can use the ask foe number

Heres the updated game :slight_smile:

2 Likes

I feel like you have the right idea with your initializeLevel function, since you pass it a value that states what level you want to load:

image

You should be able to call this function from anywhere in your code to get a level started, whether it’s restarting a level or loading a level from the beginning of the game.

Let us know if you get stuck.

2 Likes