Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Variable adding random value to list
- Hystccc
-
Scratcher
33 posts
Variable adding random value to list
So in the game when you press the correct button that correlates to the arrow it adds how long it took u to press it to the list, some of the times when you do it, it adds a random value that is usually 0.034, i dont know why it does that
https://scratch.mit.edu/projects/1317833040
https://scratch.mit.edu/projects/1317833040
- Sammies123333
-
Scratcher
500+ posts
Variable adding random value to list
I think if you just hold wasd all at the same time, it instantly does all of them
- Hystccc
-
Scratcher
33 posts
Variable adding random value to list
I think if you just hold wasd all at the same time, it instantly does all of themHow do i fix it?
- EpsilonX
-
Scratcher
95 posts
Variable adding random value to list
I think you need to ensure that the other buttons aren't being pressed. You should replace your wait blocks with these wait blocks: (in order)
wait until <<key [w v] pressed?> and <not <<key [d v] pressed?> or <<key [s v] pressed?> or <key [a v] pressed?>>>>>
wait until <<key [d v] pressed?> and <not <<key [w v] pressed?> or <<key [s v] pressed?> or <key [a v] pressed?>>>>>
wait until <<key [s v] pressed?> and <not <<key [w v] pressed?> or <<key [d v] pressed?> or <key [a v] pressed?>>>>>
wait until <<key [a v] pressed?> and <not <<key [w v] pressed?> or <<key [d v] pressed?> or <key [s v] pressed?>>>>>
- g6g6g66g6g
-
Scratcher
100+ posts
Variable adding random value to list
How do i fix it?The simplest way is to wait until the user is not pressing any keys to generate the next arrow, and to penalize the user for pressing the wrong key even if they also pressed the correct key. Instead of chaining many booleans together you can loop over all the possible keys by
- Adding all of the keys to a list, and
- Changing the costume names to the keys.
- The key matches the generated arrow and the key was pressed
- The key does not match the generated arrow and the key was not pressed.
DEMO
There is an alternate slightly more complicated way, which is only counting key presses if they were pressed just now, ignoring any keys that are held. I can expand on this if you'd like.
- Discussion Forums
- » Help with Scripts
-
» Variable adding random value to list