Godot Version
Godot v4.3.stable
Question
I’m creating a system to accept both controller and keyboard+mouse inputs, and change things like UI accordingly. However to do this, I need to check if an input is from a joypad or k+m, and so I don’t have a big if/else script, I’m using the following code:
extends Node
signal input_mode_changed
enum InputModes {
KEYBOARD,
CONTROLLER
}
var current_input_mode := InputModes.KEYBOARD :
set(new_input_mode):
current_input_mode = new_input_mode
input_mode_changed.emit()
var keyboard_inputs := [InputEventKey, InputEventMouse]
var controller_inputs := [InputEventJoypadMotion, InputEventJoypadButton]
func _input(event: InputEvent) -> void:
if keyboard_inputs.has(event.get_class()):
current_input_mode = InputModes.KEYBOARD
else:
current_input_mode = InputModes.CONTROLLER
However, even when the event class is contained by the keyboard_inputs array, it never returns true, so the input mode is always CONTROLLER. I know that for this an else/if could work without much problem, but I want to at least understand why it does not work.