Lunar wolf
Lunar wolf

Reputation: 1

I don't know why but one out of 5 sprites I created in Scratch is not working as desired

I was trying to make a simple game using scratch but my lives counter is not working for one of the object. It is working for other 2 sprites. Everything is same. See if anyone can help.

Upvotes: 0

Views: 689

Answers (1)

Ruud Helderman
Ruud Helderman

Reputation: 11018

From your project:

if (y position) = (-178) then

This is a bad idea. When a sprite 'glides', it will do so in small steps. Those steps are not guaranteed to be integer, and they are also not infinitesimal. Meaning that the sprite may well skip y position -178, for example by stepping from -177.99 to -178.01. Turn on the stage monitor of that sprite's y position block, and you'll get the idea; notice the fractional digits.

The solution: instead of checking if y position is exactly -178, check if it is less than -178.

if (y position) < (-178) then

So why didn't the other two sprites have the same problem? It was in the costume. Scratch always makes sprites stop before the costume fully leaves the stage; always maintaining at least 30 pixels of overlap. Each sprite has a different costume, making them stop at a different y position. In the other two sprites, that y position just happened to match the number in the code. I recommend to make the suggested change in those sprites as well, to prevent the game breaking again in case you (or a remixer) ever changes costumes. Make sure to keep some slack space.

Upvotes: 3

Related Questions