Game Lab and Multiple KeyDown

I have a student who would love to code in different results into a if block. She would like to use space bar to achieve this, for example, is space bar is struck once, something happens, but if there is a double click on the space bar, or a triple click, different things happen. Is there code that will allow this? I’ve search and don’t see an “right there” way to do this. Thoughts?

Hi @mcmastersha,

I think the best way to achieve an action on multiple clicks is to add to a variable each time the space bar is clicked and then have the if statement respond to the value of the variable. So, the variable would begin at 0 and with each space bar click, 1 would be added to the variable. If the variable = 1, one action is taken. If the variable = 2, another action is taken. The variable could reset if > 3 if needed.

Will that work?
~Michelle

1 Like

There are a few different ways, however, this youtube channel has some excellent tutorials for those advanced students.
[Multicolor Shots, Keeping Score, Multiple Targets in Game Lab on Code.org - YouTube](https://youtube channel)

Thank you so much! This is why one of the reasons why I love using this curriculum! Great community work involved here :slight_smile:

Start with @melynn advice and add a count on the space bar. You need to use the draw() loop to decide how long you wait for multiple clicks.

Like this