# How do I to get the average time of clicks

Get help using Construct 2

### » Wed Jun 10, 2015 5:44 pm

I need to register the average time a player takes to click a several sprites (for example: a image will be appear 10 times and I need to know how much time (ms) the player takes to click on each of them). So, I'll need to register this time and get the average after to show when he's finishes the interaction. Could anyone help me? Thanks.
B
74
S
14
G
4
Posts: 1,050
Reputation: 8,203

### » Wed Jun 10, 2015 6:27 pm

You can use the "dt" (delta time) expression to get the amount of time elapsed since last tick. Add "dt" to a variable on tick, and when the button is pressed, get the value in the variable and put it in a list of recorded times, and then set the time keeping variable back to 0. At the end, you take the average by adding all the times in the list together, then dividing by the number of times in the list. So you would be dividing by 10 after adding all the times together.

Alternatively you can also use Timers to record how much time has passed. Instead of adding delta time every tick, you could set a timer to execute every 0.1 seconds, and add 0.1 to the time keeping variable. This would be more optimal as you're not doing something every tick, only every 0.1 seconds, however this would be accurate only to a tenth of a second. You could decrease the timer interval to increase accuracy.
B
12
S
4
Posts: 48
Reputation: 910

### » Wed Jun 10, 2015 6:56 pm

You can use 'wallclocktime' and just subtract the last value from the current value. You don't need to keep track of the time directly, just store that time on a click and use that as a reference on the next click.
B
71
S
22
G
279
Posts: 3,838
Reputation: 153,878

### » Wed Jun 10, 2015 7:37 pm

blackhornet wrote:You can use 'wallclocktime' and just subtract the last value from the current value. You don't need to keep track of the time directly, just store that time on a click and use that as a reference on the next click.

That's a good solution, I wasn't aware of "wallclocktime".

To add to that, I would suggest you store the time when the next button spawns, rather than on click in case there is a delay between buttons.
B
12
S
4
Posts: 48
Reputation: 910

### » Wed Jun 10, 2015 7:46 pm

Thank you, guys.

One doubt @blackhornet: if I use "wallclocktime", I'll need to get the time when the image1 appear, get it again on click and subtract these two values after, get the time again when the image2 appear ...., but how can I get the average time when the interaction stop?
B
74
S
14
G
4
Posts: 1,050
Reputation: 8,203

### » Wed Jun 10, 2015 7:55 pm

You still need to store each difference. Use an Array.

Edit: Or, keep a running total and divide by 10 after ten clicks.
B
71
S
22
G
279
Posts: 3,838
Reputation: 153,878

### » Wed Jun 10, 2015 8:06 pm

blackhornet wrote:Edit: Or, keep a running total and divide by 10 after ten clicks.

Nice. Thank you.
B
74
S
14
G
4
Posts: 1,050
Reputation: 8,203