Discuss Scratch
- Mad__Moss
-
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:
Anybody else think that this is a good idea?
From Mad__Moss
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)]> thenInstead of having:
...
end
if <<<<<key [... v] pressed?> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> or <key [... v] pressed?>> thenAnd needing to repeat and change that every time you changed your mind.
...
end
Anybody else think that this is a good idea?
From Mad__Moss
- stickfiregames
-
1000+ posts
"Key Pressed" Sensor Reporter Block
What would it report if more than one key was pressed?
- MegaApuTurkUltra
-
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_oneRequiredThe 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.
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
Last edited by MegaApuTurkUltra (Sept. 28, 2014 15:25:59)
- Mad__Moss
-
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
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
- Mad__Moss
-
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?
- RPFluffy
-
1000+ posts
"Key Pressed" Sensor Reporter Block
Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
- Langdon35
-
500+ posts
"Key Pressed" Sensor Reporter Block
Yes it does, also, I think it would be a better idea to use this than make a new block :3Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
Last edited by Langdon35 (Sept. 29, 2014 00:20:26)
- RPFluffy
-
1000+ posts
"Key Pressed" Sensor Reporter Block
Yes it does, also, I think it would be a better idea to use this than make a new block :3Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
Um, that's basically what I said don't do that, its called spam FYI
- Mad__Moss
-
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
Whelp, never mind,
Mad__Moss
- Mad__Moss
-
100+ posts
"Key Pressed" Sensor Reporter Block
Really? Anyone have more ideas on how the block would work?
- Langdon35
-
500+ posts
"Key Pressed" Sensor Reporter Block
Ok, thanks for the info.Yes it does, also, I think it would be a better idea to use this than make a new block :3Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
Um, that's basically what I said don't do that, its called spam FYI
maybe this: Really? Anyone have more ideas on how the block would work?
if <keys pressed> then //there would be a check box list of keys that could be pressed.
...
end
- theonlygusti
-
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:
But add me to the support list!
(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!
- Mad__Moss
-
100+ posts
"Key Pressed" Sensor Reporter Block
Ok, thanks for the info.Yes it does, also, I think it would be a better idea to use this than make a new block :3Try this ^ Try some hacksdefine 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 1define keyPressesInList_oneRequiredThe 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.
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
It works…
Um, that's basically what I said don't do that, its called spam FYImaybe this: Really? Anyone have more ideas on how the block would work?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:That way you could change the keys that need to be pressed more easily.
...
end
- Mad__Moss
-
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:
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
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
- MegaApuTurkUltra
-
1000+ posts
"Key Pressed" Sensor Reporter Block
Scratch string comparisons are case insensitive, so
Then replace
<[A]=[a]> // is trueWhat 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)With
repeat(...)
...
switch costume to [default v]HTH
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))
...
- Mad__Moss
-
100+ posts
"Key Pressed" Sensor Reporter Block
I don't know how you come up with this stuff.
- Langdon35
-
500+ posts
"Key Pressed" Sensor Reporter Block
Ok, well you guys have fun, I leaving this discussion.