+1 vote

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.

in Engine by (195 points)
edited by

event.is_echo is true by any chance?

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.

What if you use _input instead?

3 Answers

0 votes
Best answer

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.isactionpressed("leftmouseb") or ev. isactionreleased("leftmouseb").

by (195 points)
0 votes

set line:

d+=1

to:

d=d+1

Check if your touchpad is flickering?

by (438 points)

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

+2 votes

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).

by (80 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.