Help on my code. EMERGENCY

Is there any thing wrong with this code. What I am trying to do is when player overlaps with treasure and has under 2 life then add a life, or else add 1 point. When I tried it in the arcade it doesn’t seem to work. The heart won’t even be destroyed. Help please!!!

1 Like

Can you include a link to your game? It can help users debug faster.

1 Like

Off the top of my head, I’d guess you need to change the condition to
if ( life <= 1). Notice that the score part of the statement never will destroy the heart, since there’s no destroy block inside.

Also, you want to destroy ‘otherSprite’ instead of ‘Winner’ since there are lots of ‘Winner’ hearts being created and you only want to destroy the one that has been overlapped.

Finally, notice that the overlap statement uses ‘Treasure’ and the projectile uses ‘treasure’. I believe that the program sees those as two separate kinds.

Hope that helps!

Yes sure. Here is the link

Yep, those changes work. Here’s the code that I modified to test it.
Screenshot by Dropbox Capture

Notice that I had to remove the “treasure” variable from the field and then select the ‘Treasure’ kind from the dropdown list.

It’s looking really good so far!

OMG. THANKYOU SOOOOO MUCH. This is for my assessment task, it worked!!! Also what code should I use if I want to make that if you miss a spaceship it is the end of the game?

1 Like

Ooh, there’s a couple of things you could do there.

  1. Add a sprite to the left side and when the ship collides with the sprite, the game is over
    (See this tutorial -

  2. Since you already have ships auto destroy, you can use the “on sprite destroyed” block and put a game over inside of that…but if you do, you’ll need to change the ship’s type when it’s hit by a projectile or else hitting the ship with a projectile will end the game, too.

Also on the on start block, when I reached 80 score it does’t seem to appear “Good job, you win” on the screen.

It doesn’t look like you’re telling it to. Do you have this block anywhere?
Screenshot by Dropbox Capture

I have this block here

What does it mean when I need to change the ship’s type.

actually is it possible to make if you miss a spaceship you lose a life?

Also can I import music from outside into makecode?

I mean to change the ship’s kind, like I showed in the sample blocks:


You can make it lose a life by adding a change life by -1 instead of a game over.

Then, make sure that you not only change the message of the game over, but call the game over, too:
Screenshot by Dropbox Capture

Finally, we don’t have a way to import a song directly, but if you have the sheet music for it, you can recreate it using our music editor :slight_smile:

Ok sure, thankyou so much

Whenever enemy touches the main character, I lose the game completely but I had 2 hearts so idk why I lose game when I am supposed to be on 1 life in total

Would you please include the link for the newest version of your game?

I fixed the problem, thank you