Discuss Scratch

Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Hi,

I had an idea, what about a Sensor Reporter block that contained the key that was currently being pressed? If this existed, then you could have a list with all the keys that perform a specific function in it and make:
if <[Task 1 Keys v] contains [(key pressed)]> then
...
end
Instead of having:
if <<<<<key [... v] pressed?> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> then
...
end
And needing to repeat and change that every time you changed your mind.

Anybody else think that this is a good idea?

From Mad__Moss

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
stickfiregames
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

What would it report if more than one key was pressed?










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
MegaApuTurkUltra
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

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.

Last edited by MegaApuTurkUltra (Sept. 28, 2014 15:25:59)


$(".box-head")[0].textContent = "committing AT crimes since $whenever"
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

If more than one key was pressed then it would report the last key that was pressed, for example, if I pressed “W”, (key pressed?) would set itself to “W”, then if I pressed “G” while still holding down “W”, (key pressed?) would set itself to “G”, and if nothing was pressed then it would set itself to “”, nothing.

This way you could also check to see if no keys were being pressed.

MegaApuTurkUltra (hope I got that right), you are * with scripts but I thought this might make it easier for someone who is new to (too?) Scratch and wants to make something a bit more complicated. also it would make the creation of 1s1s projects a lot easier.

From Mad__Moss

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Apparently we can't say the most used term in Borderlands 2 in the forums, does Scratch give users warnings for profanity?

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
RPFluffy
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

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…

Nothing Is EVER 100%, that is just an assumption.















Some important links: Here and here or need help click Here. Eats followers, Loves helping people.
My “..” and “…” are not spelling mistakes, it means that they are ways of telling someone that I can continue more about it and that the sentence isn't ended the best way. I like putting new indents and lines so I can split up what I am talking about.




































Some important links: Here and here or need help click Here. Eats followers, Loves helping people. Check this MMO out! Kiwi = Support WHAT THAT'S IMPOSSIBLE: Through the drop down ;)
if <> :: control cstart

else :: control
end
Langdon35
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

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

Last edited by Langdon35 (Sept. 29, 2014 00:20:26)


Woohoo!
RPFluffy
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

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

Nothing Is EVER 100%, that is just an assumption.















Some important links: Here and here or need help click Here. Eats followers, Loves helping people.
My “..” and “…” are not spelling mistakes, it means that they are ways of telling someone that I can continue more about it and that the sentence isn't ended the best way. I like putting new indents and lines so I can split up what I am talking about.




































Some important links: Here and here or need help click Here. Eats followers, Loves helping people. Check this MMO out! Kiwi = Support WHAT THAT'S IMPOSSIBLE: Through the drop down ;)
if <> :: control cstart

else :: control
end
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Meh, OK. wasn't really sure about the idea in the first place, also, I don't know how hard it is for the Scratch Team to implement a new block so yeah.

Whelp, never mind,
Mad__Moss

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
stickfiregames
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Support this.










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Really? Anyone have more ideas on how the block would work?

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
Langdon35
Scratcher
500+ 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
Ok, thanks for the info.

Mad__Moss wrote:

Really? Anyone have more ideas on how the block would work?
maybe this:
if <keys pressed> then //there would be a check box list of keys that could be pressed.
...
end

Woohoo!
theonlygusti
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

I'm not sure, but I think I've suggested this as well. But I totally agree that a (key pressed) block would be a brilliant idea, but maybe with a different name, some suggestions:

(key pressed :: sensing reporter)
(pressed key :: sensing reporter)
(currently pressed key :: sensing reporter)
(current key press :: sensing reporter)

But add me to the support list!

Langdon35
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

Support, I guess.

Woohoo!
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Langdon35 wrote:

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
Ok, thanks for the info.

Mad__Moss wrote:

Really? Anyone have more ideas on how the block would work?
maybe this:
if <keys pressed> then //there would be a check box list of keys that could be pressed.
...
end

Or you could have a list with the keys you want to be pressed:
if <(item (all v) of [Key List v]) = [(key pressed)]> then //If ALL of the items in Key List are pressed then:
...
end
That way you could change the keys that need to be pressed more easily.

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

On the subject of keys being pressed, maybe a more refined typespace (I think I made that word up). I have a project that I was making as a global communicator (Yes I know you can't have those but I just wanted to see if I could do it), one of the scripts is:

define Naming
set [Namer v] to (join (Name) [: ])
set [Name v] to []
set [Counter v] to [1]
repeat (length of (Namer))

set [Loop v] to [1]
repeat (length of [Characters v])

if <(item ((Loop v)) of [Characters v]) = (letter (Counter) of (Namer))> then

if <<(length of (Loop)) = [1]> or <(Loop) = [10]>> then

set [Name v] to (join (Name) (join [0] (((Loop)) - (1))))
else
set [Name v] to (join (Name) ((Loop) - (1))
end
change [Loop v] by (1)
end

end
change [Counter v] by (1)
end
stop [this script v]

The “Characters” list has all the letters (A-Z) then all the lettters (a-z) then numbers, then other symbols.

At the start I set the “Name” variable to “Mad__Moss”, then the “Namer” variable would be set to “Mad__Moss: ”, and the “Name” variable set to “”. It would then run the script, and what the end result of the “Name” variable should be is “1226298282124044448794” (12-26-29-82-82-12-40-44-44-87-94), which means “Mad__Moss: ”, but instead it is set to “123800260329828212381440184418448794” (12-38-00-26-03-29-82-82-12-38-14-40-18-44-18-44-87-94), which means “MmAaDd__MmOoSsSs: ”

I personally think that this needs to be solved (mostly because I'm having a bet with my friend on if I could actually do it in a certain time period), but also for …… I'll get back to you later on that.

Does anyone know if their is a way to fix this?
Mad__Moss

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
MegaApuTurkUltra
Scratcher
1000+ posts

"Key Pressed" Sensor Reporter Block

Scratch string comparisons are case insensitive, so
<[A]=[a]> // is true
What this is doing is making letters match 2 items in your characters list: the capital and lowercase. What you need to do is separate capital and lowercase with all lowercase before all capital, and symbols and numbers at the end. Then add 26 blank costumes named for all capital letters and a default costume, which should be the first costume, to your sprite (switching costumes is case sensitive so we can use it to detect capital letters)
Then replace
set [Loop v] to (1)
repeat(...)
...
With
switch costume to [default v]
switch costume to (letter (Counter) of (Namer))
if<not<(costume #)=(1)>> //capital letter matched
set [Loop v] to [number of first capital letter in list]
else
set [Loop v] to (1)
end
repeat(((length of [Characters v])-(Loop))+(1))
...
HTH

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

I don't know how you come up with this stuff.

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.
Langdon35
Scratcher
500+ posts

"Key Pressed" Sensor Reporter Block

Ok, well you guys have fun, I leaving this discussion.

Woohoo!
Mad__Moss
Scratcher
100+ posts

"Key Pressed" Sensor Reporter Block

Bye Bye!

Like Minecraft? How about you Build Your Own Aquarium!
Need to calm down? Watch and listen to Something Relaxing.
Want to know how loud something is? Try This or This!
Have time to waste? See how far you can go Clicking Fruit, or Dodging Spheres.

Powered by DjangoBB