Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » I'm using a LOT of else if blocks. Will this lag my project?
- -Cold-lord-X-
-
Scratcher
100+ posts
I'm using a LOT of else if blocks. Will this lag my project?

I think there is a better way to do this, but im not sure.
I'm trying to detect all 26 letters of the alphabet as a key press, and the enter key (which IS possible, by the way.)
However, this seems like an excess amount of blocks, and im not sure if it will bode well with low end devices.
Any better ways?
- awesome-llama
-
Scratcher
1000+ posts
I'm using a LOT of else if blocks. Will this lag my project?
Since the key pressed block can have a reporter block placed in its input, you could instead use a loop to iterate over all the keys you want to check.
Having the keys in a list would probably be the best option, that way you just need to do this:
Having the keys in a list would probably be the best option, that way you just need to do this:
define check for keysIf you want a project example, see: https://scratch.mit.edu/projects/637041340/
// set to run without screen refresh to make the loop run fast
set [i v] to [1]
repeat (length of [key names v] :: list)
if <key (item (i) of [key names v] :: list) pressed?> then
... // key was pressed, relevant code goes here
end
change [i v] by (1)
end
- 09878901234321
-
Scratcher
500+ posts
I'm using a LOT of else if blocks. Will this lag my project?
No, it won't but awesome-llama's script is good.
I made this a while back:
https://scratch.mit.edu/projects/835709331/
I made this a while back:
https://scratch.mit.edu/projects/835709331/
- Discussion Forums
- » Help with Scripts
-
» I'm using a LOT of else if blocks. Will this lag my project?


