Mad__Moss

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

stickfiregames

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

MegaApuTurkUltra

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.

Mad__Moss

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

Mad__Moss

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

RPFluffy

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…

Langdon35

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

RPFluffy

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

Mad__Moss

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

stickfiregames

Support this.

Mad__Moss

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

Langdon35

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

theonlygusti

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

Support, I guess.

Mad__Moss

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.

Mad__Moss

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

MegaApuTurkUltra

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

Mad__Moss

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

Langdon35

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

Mad__Moss

Bye Bye!