Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Making a costume changed based on what key you pressed?
- Joe_America_BIden
- Scratcher
8 posts
Making a costume changed based on what key you pressed?
I'm currently making a game where the premise is typing the alphabet as fast as you can. I have costumes for every single letter of the alphabet and i am just wondering how can you detect if the key you pressed corresponds to the costume (the name or number of the costume). And then when it detects the right key pressed then switches to the next costume.
Last edited by Joe_America_BIden (April 1, 2024 10:34:05)
- PutneyCat
- Scratcher
500+ posts
Making a costume changed based on what key you pressed?
Something like:
set costume to a
repeat until costume name = success (a costume immediately after z)
if key (costume name) pressed
next costume
set costume to a
repeat until costume name = success (a costume immediately after z)
if key (costume name) pressed
next costume
- Joe_America_BIden
- Scratcher
8 posts
Making a costume changed based on what key you pressed?
Something like:
set costume to a
repeat until costume name = success (a costume immediately after z)
if key (costume name) pressed
next costume
Thank you for the code. I appreciate it!
- Kirbydogs-Alt
- Scratcher
36 posts
Making a costume changed based on what key you pressed?
If you are looking to make it case sensitive (e.g. if you press Shift+A), things can get tricky due to the fact that Scratch has removed all ways to sense the shift key being pressed, but you can substitute the shift key for something like @ or ~, which require they shift key to be pressed. You can do something like this:Something like:
set costume to a
repeat until costume name = success (a costume immediately after z)
if key (costume name) pressed
next costume
Thank you for the code. I appreciate it!
when green flag clickedQuick thing to note: Scratch also doesn't care about case sensitivity, so costumes are generally used to represent case sensitivity, since costumes aren't affected by this. That being said, you still can't do something simple to detect case sensitivity, more technical things are used, which can be found here, on the Scratch Wiki.
forever
if <key [~ v] pressed?> then
set [shift? v] to [true] // When the tilde key is pressed, it kind of acts like a light switch; once flipped, you un-press it and then press a key like k to make it a capital K.
wait until <key [k v] pressed?>
switch costume to [k2 v] // You could do this for each and every letter, but I'm sure there is a better way that I am currently unaware of.
end
Last edited by Kirbydogs-Alt (April 1, 2024 14:40:34)
Select some text, and then hold {shift} and the down arrow key to see full signatures!
Hey there, I'm Kirbydogs, and uh idk what to put here lol
- Discussion Forums
- » Help with Scripts
- » Making a costume changed based on what key you pressed?