Discuss Scratch

wimpygirl6
Scratcher
61 posts

"Key Pressed" Sensor Reporter Block

RPFluffy wrote:

Langdon35 wrote:

RPFluffy wrote:

MegaApuTurkUltra wrote:

Try some hacks

define keyPressesInList_allRequired
set [i v] to (1)
repeat (length of [presses v])
if <not<key (item (i) of [presses v]) pressed?>>
set [yes v] to (0) // idk if key pressed accepts a reporter. Try it! Otherwise edit the json
stop [this script v] // if not ALL keys in the list are pressed, return 0
end
change [i v] by (1)
end
set [yes v] to (1) // all keys in list pressed, return 1
define keyPressesInList_oneRequired
set [i v] to (1)
repeat (length of [presses v])
if <key (item (i) of [presses v]) pressed?>
set [yes v] to (1)
stop [this script v] // if at least ONE of the keys is pressed, return 1
end
change [i v] by (1)
end
set [yes v] to (0) // no keys in the list are pressed, return 0
The stop […] blocks are in there to prevent unnecessary looping, which will slow your project down. Make sure to use custom blocks like above because then stop this script will only stop the custom block. Also make sure to make the custom blocks run without screen refresh to speed up the looping.
Try this ^
It works…
Yes it does, also, I think it would be a better idea to use this than make a new block :3

Um, that's basically what I said don't do that, its called spam FYI
WHOA!!!!!!
ScratchDiogoh
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Hello!
when green flag clicked
forever
if <not <key [any v] pressed?>> then
delete (1 v) of [list v]
end
if <key [space v] pressed?> then
replace item (1 v) of [list v] with [space]
end

end
Make all the keys

+1700 Bad Posts
Eli3210
Scratcher
21 posts

"Key Pressed" Sensor Reporter Block

I had the same idea and found a simple way to do so.
Use this script:
when green flag clicked
forever
if <key [ (item (Any)) of Key List pressed?> then
-your script goes here
end
end
Enjoy!
Sorry that Scratch didn't put the script together right.
(P.S: the “Any” variable has a value of “any”)

Last edited by Eli3210 (Aug. 23, 2019 22:25:55)


Hello! My name is Eli3210! I am a Scratcher who is willing to help debug a script or create an element! I am sometimes on Scratch.
Feel free to comment on my profile and request help!

Here is a random cat fact:
(COMING SOON)
Nambaseking01
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

I don't understand. Doesn't this block already exist?

<key [c v] pressed?>

I have a feeling I am missing something. Could someone please explain?

Last edited by Nambaseking01 (Aug. 24, 2019 11:17:15)


Hey there! My name is Nammy. I'm a male Forum Helper and Scratch Wiki Editor.
Profile | Test Account | Talk with me here! | Griffpatch is quitting Scratch?!
46009361
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Nambaseking01 wrote:

I don't understand. Doesn't this block already exist?

<key [c v] pressed?>

I have a feeling I am missing something. Could someone please explain?
Yes, this block exists, but the suggestion is about asking which keys are pressed, not if a key is pressed. Like this:

(which keys pressed? :: sensing)

Anyway, I created a workaround for this block recently (which I commented on @CombaticonsCombine but then got deleted less than an hour after). The link to the project is:

https://scratch.mit.edu/projects/328947478/

Please check it out as it only has 2 views at the time of writing! There is even a discussion forum for this project at https://scratch.mit.edu/discuss/topic/369833/!

Edit: Be sure to give credit when you backpack my script! It's part of Scratch's Community Guidelines.

Last edited by 46009361 (Sept. 19, 2019 18:12:41)


Inspired by coder2045—which, in turn, got inspired by Mr_PenguinAlex.
What's wrong with these blocks? There are zero mistakes because no round has started yet. Beware that some of the mistakes don't relate to the Scratch blocks below.
// No round has started yet.
Be the first to comment all of the mistakes on my profile correctly and you'll get a love! You can't comment any mistakes right now because there are none!
PlayerXS
Scratcher
80 posts

"Key Pressed" Sensor Reporter Block

Sensing :: sensing hat
(Key Pressed :: sensing reporter)
Yeah I had that idea too.

Last edited by kaj (Tomorrow 00:00:00)
Nambaseking01
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

I think this would be useful because a lot of people want it and the workaround is not the simplest for New Scratchers.

But I think Proli's system could give you a better understanding of how to recreate this in a simple manner.

Hey there! My name is Nammy. I'm a male Forum Helper and Scratch Wiki Editor.
Profile | Test Account | Talk with me here! | Griffpatch is quitting Scratch?!
sathvikrias
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

here is a workaround, which doesn't involve doing letter-for-letter:
define find key pressed
forever
if <key [any v] pressed?> then
set [keys v] to (keys you want to detect::undefined)
set [incroment v] to [1]
repeat (length of (keys)::operators)
if <key (letter (incroment) of (keys)) pressed?> then
set [key pressed v] to (letter (incroment) of (keys))
end
change [incroment v] by (1)
end
if <key (join [enter] []) pressed?> then
set [key pressed v] to [enter]
end
if <key [space v] pressed?> then
set [key pressed v] to [space]
end
say (key pressed)
else
say [no key is pressed]
end
end

Last edited by sathvikrias (Oct. 23, 2020 22:30:13)


Moving from Scratch? Don't learn C or Java, try Snap!
moonwatcher348
Scratcher
34 posts

"Key Pressed" Sensor Reporter Block

@sathvikrias that doesn't work, I see no reason it shouldn't though
Futurebot5
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

sathvikrias wrote:

here is a workaround, which doesn't involve doing letter-for-letter:
define find key pressed
forever
if <key [any v] pressed?> then
set [keys v] to (keys you want to detect::undefined)
set [incroment v] to [1]
repeat (length of (keys)::operators)
if <key (letter (incroment) of (keys)) pressed?> then
set [key pressed v] to (letter (incroment) of (keys))
end
change [incroment v] by (1)
end
if <key (join [enter] []) pressed?> then
set [key pressed v] to [enter]
end
if <key [space v] pressed?> then
set [key pressed v] to [space]
end
say (key pressed)
else
say [no key is pressed]
end
end
That workaround is to long for how useful the suggestion is.

So…hello, ou bonjour, o hola, o ciao, oder hallo.

bluedragon8633
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Support, this also goes for touching sprites. If I have 10 different enemy sprites, it's easier to write
if <[enemy list] contains <touching [sprite] ?> ?> then
broadcast [hurt]
end
Now, if you touch any enemy on the list, it broadcasts hurt, rather than doing this:
<<<touching [enemy1] ?>> or <<<touching [enemy2] ?>> or <<<touching [enemy3] ?>> or <<<touching [enemy4] ?>> or <<<touching [enemy5] ?>> or <touching [enemy6] ?>>>>>>
sathvikrias
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

Futurebot5 wrote:

That workaround is to long for how useful the suggestion is.
I know, but at least it's less tedious

Moving from Scratch? Don't learn C or Java, try Snap!

Powered by DjangoBB

Standard | Mobile