Search code examples
mit-scratch

Why doesn't the sprite stay hidden after being touched?


I have this script in Scratch for a sprite (also viewable in MIT's editor):

Screenshot of code

When Kai touches the sprite it only disappears briefly, but then remains visible even though Kai is still touching it. Isn't it supposed to only be visible once Kai has removed from the sprite altogether?


Solution

  • The problem here is that you cannot touch a hidden sprite. So the code runs like this:

    1. Kai is touching Line so the Line hides

    2. As you can't touch a hidden sprite Kai is not touching Line so the line shows.

    A quick solution is to use the [set (ghost) effect to (100) ] instead of [hide ] and [set (ghost) effect to (0) ] instead of [show ]. This will work because you can touch an invisible/ghost sprite so now it runs like this:

    1. Kai is touching Line so the Line "hides"

    2. Kai is still touching the Line's ghost so the Line will keep "hiding"

    3. Let's say that Kai moves and stops touching the line

    4. Kai is not touching the line anymore so the Line will "show".