I'm trying to make it so the player can select an option from the hotbar through the numbers on their keyboard, but it seems tedious to set individual input methods for 1, 2, 3, 4 , 5, 6, 7, 8 and set active_slot to each one in individual if statements like I am, faster way of doing this?
checking for large amount of input (1-8)
- Best Answerset by Carvii
You can detect key presses by scan code. It is usually not a good idea (particularly for letter keys, as there are different keyboard layouts for each language). However, for numbers it should be fine because I think the scan codes are universal.
func _input(event):
if event is InputEventKey and event.is_pressed():
match(event.scancode):
KEY_0:
print("0 pressed")
KEY_1:
print("1 pressed")
KEY_9:
print("9 pressed")