Godot: _input() pressing keys while cheking index causes error

Created on 16 Mar 2020  路  1Comment  路  Source: godotengine/godot

Godot version:
3.2.1
OS/device including version:
ubuntu 19.10
Issue description:
On the _input(event) func if the user checks for button_index (which is a mouse button) but if the player has pressed a key it generates an error.
Ps: This is working right, but if the user presses a key, not a mouse button button index should return at least -1 and not generate a error.

Steps to reproduce:

  • attach the below script to a Control Node
func _input(event):
    if (event.is_pressed() and event.button_index == BUTTON_RIGHT):
        print("pressed")
        pass

*Run the game
*press delete key
*should happen something like this:
Screenshot from 2020-03-16 08-50-41

** There is a workaround?
Checking if event.button_index != null will return a error too so the workaround was:
if event is InputEventMouseButton above the code mentioned.

Minimal reproduction project:
N/A

archived

Most helpful comment

Hi,
It makes sense from my underdstanding.
The "event" parameter in _input is an object of the class InputEvent, or any of the classes that inherit it. Those cover mouse, keyboard, midi input ...
button_index is a property of InputEventMouseButton. And not at all related to keyboard input (InputEventKey)
So it's up to you to check which type of event you are expecting with if event is InputEventMouseButton, or if event is InputEventMouseMotion ...

>All comments

Hi,
It makes sense from my underdstanding.
The "event" parameter in _input is an object of the class InputEvent, or any of the classes that inherit it. Those cover mouse, keyboard, midi input ...
button_index is a property of InputEventMouseButton. And not at all related to keyboard input (InputEventKey)
So it's up to you to check which type of event you are expecting with if event is InputEventMouseButton, or if event is InputEventMouseMotion ...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

testman42 picture testman42  路  3Comments

rgrams picture rgrams  路  3Comments

blurymind picture blurymind  路  3Comments

mefihl picture mefihl  路  3Comments

gonzo191 picture gonzo191  路  3Comments