Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_input called once per frame while key is held #8895

Open
j-h-a opened this issue May 8, 2024 · 3 comments
Open

on_input called once per frame while key is held #8895

j-h-a opened this issue May 8, 2024 · 3 comments
Labels
bug Something is not working as expected

Comments

@j-h-a
Copy link

j-h-a commented May 8, 2024

Describe the bug (REQUIRED)

on_input is called every frame while a bound key is held, but it should only be called when the key is pressed, repeated, or released.

To Reproduce (REQUIRED)

  1. Create an empty project
  2. add one key to the input binding and remove the mouse binding
  3. add a single game object
  4. create and add a script to the game object
  5. paste this code into the script
function init(self)
	msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action)
	print(action_id, "pressed:", action.pressed, "released:", action.released)
end
  1. Run the app
  2. press and hold the bound key
  3. Look at the console output to see bug being demonstrated

Expected behavior (REQUIRED)

You should see just one line of output in the console:
DEBUG:SCRIPT: hash: [my_action] pressed: true released: false

Actual behavior

You see the expected line in the console, then another line getting repeated every frame:
DEBUG:SCRIPT: hash: [my_action] pressed: true released: false
[n++] DEBUG:SCRIPT: hash: [my_action] pressed: false released: false

Defold version (REQUIRED):

  • 1.8.0

Platforms (REQUIRED):

  • macOS Sonoma 14.4.1
  • Mac

Minimal repro case project (OPTIONAL):
input_bug.zip

@britzl
Copy link
Contributor

britzl commented May 13, 2024

Ah, no, the pressed and released states happen only once on the frame when the input was first pressed or released. It will not repeat. Note that there is also a repeated state which will be triggered at the configured Repeat Interval

https://defold.com/ref/go/#on_input:self-action_id-action

@britzl britzl closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@j-h-a
Copy link
Author

j-h-a commented May 13, 2024

I think this was closed without understanding the issue/report. Perhaps images will help so that you don't have to run the minimal repro project.

With a slightly modified print statement to include repeat state:
print(action_id, "pressed:", action.pressed, "released:", action.released, "repeated:", action.repeated)

Expected result (as per documentation):

Screenshot 2024-05-13 at 13 23 30 2
Pressing a key, holding it until it repeats twice (0.5s + 0.2s + 0.2s) then releasing it before the next repeat should give exactly 4 calls to on_input as per the documentation and "simulated" in the above image.

Actual Result:

Screenshot 2024-05-13 at 13 23 30
Here, on_input is called 49 times. The expected 4 plus 45 spurious calls where no event happened (all flags are false).

@britzl britzl reopened this May 15, 2024
@britzl
Copy link
Contributor

britzl commented May 15, 2024

I think this was closed without understanding the issue/report. Perhaps images will help so that you don't have to run the minimal repro project.

Sorry, I did indeed misunderstand the problem. We'll take a look. This seems like a regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants