Discuss Scratch

Zabacus
New Scratcher
2 posts

Key Pressed staying latched

Hey everyone,

I am trying to create a simple leapfrog game where the sprite has to jump onto moving lilypads and make it across a body of water while not touching the edges or missing the lilypads.

I have created a ‘'Missed Lilypad’' block that will send the Sprite back to the start if you don't make the jump and I will eventually recycle that block for when the sprite hits the edge of the screen.

The problem is that when that script is activated, it sends the sprite back to the starting location and broadcasts a message, but then seems to get caught in a loop, where it keeps broadcasting the message over and over again.

It seems to me that the Key <space> pressed? block is staying latched, meaning even though i haven't touched the space key since the last time, it still cycles through as though it has been pressed.

I know the rest of the prject needs work but for now this is a major bug that is setting me back and any insight would be greatly appreciated.

Here is the project in question:
https://scratch.mit.edu/projects/666319501

Thanks,

Zabacus

scratchusername40
Scratcher
1000+ posts

Key Pressed staying latched

It's because your “when i receive jump” always runs the “missed lilypad” block. You need to put it inside a set of if/else blocks, like this:

I tested it and it works
Zabacus
New Scratcher
2 posts

Key Pressed staying latched

That makes sense, I applied the change, thank you! But still, if I miss the first jump, its still looping through the “reset” script that should only be waiting for Space to be pressed.
The way I understand it, if i have not pressed the spacebar while the “Reset” script is active, it should not be able to leave that script. Instead, for me, i can see that it is constantly highlighted yellow, meaning it is always active, and other scripts are cycling because it is as though the space bar is always being pressed.

Last edited by Zabacus (April 7, 2022 20:00:41)

Powered by DjangoBB