I need to know the taps count in a period of time (dt)[SOLVED]

Hi, I’m working at an idle game and I need to know how many times the player tapped (touched the screen) in 2 seconds. For this i tried to use something like
if action.pressed == true and message_id ==hash( tap) then
tap_count = tap count + 1
end

but action.pressed and released is always false… what i’m doing wrong?
Thank You

Is this copy and paste from your project?

try

hash("tap")

Ohhh sorry, it was a stupid mistake…is not the code from project, now , this is my code(this code work very well for mouse left click and don’t want to work at wall for my android device and touch. And if i try without action.pressed the touch work all time while the touch is pressed, each frame :frowning: ):

function on_input(self, action_id, action)
if (action_id == hash(“mouse_lc”) or action_id == hash(“onetouch”)) and action.pressed == true then
self.alpha_tap_count = self.alpha_tap_count + 1
local speed_percent = self.alpha_tap_count * 100 / self.alpha_count

    end

end

Can you confirm that you have acquired input focus of the script and any parents that may be at a higher level?

function init(self)
        msg.post(".", "acquire_input_focus")
end

By the way, you don’t need “== true” you can just say “and action.pressed then”

function on_input(self, action_id, action)
        if action.pressed then
           print("action test")
        end
end

Does this work?

You can put code inbetween ``` to pretty print it here.

Touch event is multitouch
in your case it should be

if iaction_id == hash(“mouse_lc”) or action_id == hash(“onetouch”)) and action[1].pressed == true then

you can check it using

pprint(action)

2 Likes

Re your edit add action.released to only allow one action per input.

Hi, i think your answer can resolve my issue. I’ll test and i’ll tell you. Thank you a lot.

1 Like

We thought in the right direction, only that not action is an array but action.touch.
Something like this :

function on_input(self, action_id, action)
if ((action_id == hash(“mouse_lc”) and action.pressed == true) or (action_id == hash(“onetouch”) and action.touch[1].pressed == true)) and self.alpha_flag == 1 then
self.alpha_tap_count = self.alpha_tap_count + 1
local speed_percent = self.alpha_tap_count * 100 / self.alpha_count

            --set_speed_bar(self, speed_percent)
            if speed_percent > 100 then
                msg.post("car#script", "broken")
            end
            --print(self.alpha_tap_count)
    end

end

Thank you a lot ^)))

1 Like

yes, you are right. My mistake.

my example of using touch for a swipe : Touch screen swipe

1 Like

thank you for the swipe code. I think i’ll use it partially later. Maybe swipe it will be a better idea when a thousand of touches.