Discuss Scratch

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
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

Sammies123333 wrote:

I think if you just hold wasd all at the same time, it instantly does all of them
How 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

Hystccc wrote:

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
  1. Adding all of the keys to a list, and
  2. Changing the costume names to the keys.
When you have generated the new arrow, and the player has pressed a key (or multiple), loop through all of the keys in the list. If the player is correct, then for each key, either:
  • 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.
If this is not the case, then the player pressed the incorrect key.

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.

Powered by DjangoBB