Is ev.pressed supposed to trigger twice?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ceilingdoor
:warning: Old Version Published before Godot 3 was released.

So, my code is this:

func _unhandled_input(ev):
 if ev.pressed:
    d += 1
    get_node("Label").set_text(str(d))
 pass

This makes the label show number 2. As far as I can tell, this should be 1 as ev.pressed triggers only once, when there’s a “pressed” event happening. Looks like it triggers twice for some reason. Am I mistaken?

EDIT: Now I’m really confused. If I rewrite the code line with ev.pressed like 3 or 4 times, it triggers once, if I do that again, it triggers twice. No code is modified, I just erase the code and rewrite it the same way.

event.is_echo is true by any chance?

Bojidar Marinov | 2016-03-17 18:23

I tried using !ev.is_echo, that didn’t have any effect. The thing is that the code worked great but it just stopped working all of a sudden with no reason.

Ceilingdoor | 2016-03-18 06:15

What if you use _input instead?

Bojidar Marinov | 2016-03-18 08:57

:bust_in_silhouette: Reply From: KRL

set line:

d+=1

to:

d=d+1

Check if your touchpad is flickering?

I’ll try that as soon as I reach my PC, thanks

Ceilingdoor | 2016-03-18 06:17

:bust_in_silhouette: Reply From: Kermer

I think that something like

if (ev.type == InputEvent.MOUSE_BUTTON or ev.type == InputEvent.SCREEN_TOUCH) and ev.pressed and !ev.is_echo():

Would be more appropriate, since the 2nd time might be triggered by some other event (mouse motion or screen drag for example).

:bust_in_silhouette: Reply From: Ceilingdoor

Never mind, the question’s solved. I needed to use ev.pressed because my game runs on mobile platforms, however I’ve learned that mouse input works on mobile as well(e.g ev.is_action_pressed(“left_mouse_b”) or ev. is_action_released(“left_mouse_b”).