How to measure time between collisions and count the shortest times ?

Hi
I need a little help :slight_smile:
What I 've done:
but this code do not count first time because first prevTime= 0
Maybe I should use tables ?

local prevTime = 0  
if event.phase == "began" then  
 local timePassed = system.getTimer() - prevTime  
 prevTime = prevTime + timePassed  
 if timePassed \< 300 then  
 ballCount = ballCount + 1  
 print(ballCount)  
 end  
  
end  

[import]uid: 13156 topic_id: 20659 reply_id: 320659[/import]

Any ideas guys ? How you make combos or bonus in yours games, when user hit something very fast couple times ? [import]uid: 13156 topic_id: 20659 reply_id: 81243[/import]

in your above code, why not set the

local prevTime = system.getTimer()

at the start

[import]uid: 67619 topic_id: 20659 reply_id: 81245[/import]

hmmm prevTime will be the same passedTime then, so I will get almost zero all the time. [import]uid: 13156 topic_id: 20659 reply_id: 81247[/import]

set the initial prevTime when the level loads… [import]uid: 67619 topic_id: 20659 reply_id: 81250[/import]

Firstly vik_b_it thank you for trying help :slight_smile:

I done this but then when for example 5 balls hit the wall it will measure correctly time between collisions except first one.
I need to give bonus when exactly 5 balls hit the wall in very short interval of time

Edit*
Sorry you are right, i need the time between first one and second one and so on…
The time between first collision and prevTime doesn’t matter. The problem is with counting balls in a right way I guess. [import]uid: 13156 topic_id: 20659 reply_id: 81252[/import]