Proposed improvement to Input handling #6418
kannaOnii
started this conversation in
Engine Core
Replies: 1 comment
-
Do note that a singular event can be tied to more than just one action. So this would have to be an array of strings. See also: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Upon my testing to improve my inputs for my game, I have noticed that If statements are able to compare the Event from the _input function with the keys, buttons, or axes that trigger the Action in the Input Map, through using the methods in Input as shown below. These methods can call Actions in quotations or by the Literal, here I am using the Literal.
if Input.is_action_pressed(&"action1"): pass elif Input.is_action_pressed(&"action2") pass
My reasoning for this post is that Match statements are not able to be utilized as efficiently as a means of matching input Events with Actions. In order to achieve the same effect with Match statements, I wrote this code below.
`var inputs = [&"action1", &"action2"]
for action in inputs:
if Input.is_action_pressed(action):
match action:
"action1":
pass
"action2":
pass`
From what I can see, the Event holds which key, button, or axis was registered, and if it was pressed or released, among some other information. If statements have the advantage of calling on the Input singleton methods but not match statements. Ideally, I would like to use Match statements instead of If statements as they look cleaner.
I figured that this could be solved by tweaking the .get_action() for InputEventAction or something else to be able to get the Action that is triggered by the Event. then you can use the match statement as shown below.
match Input.get_action(event): &"action1": pass &"action2": pass
Beta Was this translation helpful? Give feedback.
All reactions