Discuss Scratch

cs646524
New Scratcher
2 posts

Holding a key

I want to make a project that requires the player to repeatedly tap a key. However, holding down the key can allow the player to cheat because the code just keeps on looping as long as the player holds down the key! How do I make the code only play once each time the player taps a key?
mstone326
Scratcher
1000+ posts

Holding a key

Put a wait until not key (whatever) key pressed. That will require the player to release the key and then press it again.
Th3_C0d3r
Scratcher
100+ posts

Holding a key

Use could use something like this…

when green flag clicked
forever
if <key [space v] pressed?> then//Wait until key is press
Do something//Do what you want ONCE
wait until <not <key [space v] pressed?>>//Wait until key is no longer held down
end
end

-Scratch On!
learncsscratch
Scratcher
100+ posts

Holding a key

You can also make it so they have to go back and forth between two keys…this can be fun for racing games and stuff…

For example:

wait until <key [a v] pressed?>
move (5) steps
wait until <key [b v] pressed?>
move (5) steps
Programmer_55
Scratcher
51 posts

Holding a key

Try this:
when [... v] key pressed
...
wait until <not <key [... v] pressed?>>
cutekitten5678
Scratcher
52 posts

Holding a key

when green flag clicked
forever
if <<touching [key sprite v] ?> and <key [(put your chosen key here) v] pressed?>> then
go to [player sprite v]
end
end
cs646524
New Scratcher
2 posts

Holding a key

Thank you! This was extremely helpful!
Galatic-Man
Scratcher
4 posts

Holding a key

Th3_C0d3r wrote:

Use could use something like this…

when green flag clicked
forever
if <key [space v] pressed?> then//Wait until key is press
Do something//Do what you want ONCE
wait until <not <key [space v] pressed?>>//Wait until key is no longer held down
end
end

-Scratch On!
thank you!

Powered by DjangoBB