+2 votes

Hi All. I have an input function that looks like this:

func _input(event):
    if event.is_action_pressed("key_L"):

in _ready() I also have this:


Yet, pressing L triggers the function multiple times.

I also tried using Input.is_action_just_pressed but that also triggers the function like 6 times...

How do I limit that to a single funtion call?

in Engine by (389 points)
#jump input
if Input.is_action_just_pressed("ui_up") and is_on_floor():
    v.y -= jumpforce

Here is a snippet of code that i have for a character jumping in a 2D world which works just fine with is_action_just_pressed. I don't want to leave you with that though because your situation seems to stretch a little further than that. Could you give more context such as implementation? is_action_just_pressed may be doing what it should but the problem may stem from what's inside the function.

thing is, there isn't anything inside the function save for a print("something") which prints 6 times with is_action_just_pressed used in _process().

I have a chest object from the game that uses that snippet of code that I just tested on that uses is_action_just_pressed to open the chest, and it only prints my echo once, I'm not certain what could be happening here but what I usually do in a situation like this to solve the problem is rewrite a simplified version in another project, and see if it behaves the same. That's what I would suggest to do in this situation.

ok i wasn't entirely honest - my function does something besides just printing. What it does is gets nodes in a group (array) and instances a mesh node for each. It then appends the instanced meshes to second array and prints that second array. The number of items in the new array is always correct but it should only print once. It printing 6 times suggests that the function is called 6 times...

I also just tried removing everything from the function and replacing it with a simple print("ok") and I got 9 ok's printed...

OK forget everything I just said, I was being stupid. I attached the input code to a generic script that is attached to several nodes on the map. Key press was triggering the function as many times as there were instances of the script in the tree, which makes total sense. I've now moved the function and input code to a singleton and the problem is gone...

Well that's perfect! I'm glad you identified the problem and found a solution.

Please log in or register to answer this question.

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.