Replies: 1 comment 3 replies
-
It might be wasting work. The way Godot figure out if an So, here is an idea: what if the method gets an array of actions to match against? that way the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I posted about this suggestion earlier on Steam, but I'll still talk about it bellow.
My suggestion is that the InputEvent objects would get the "get_action_type()" method, which will return the string of the action received by _input() method.
The idea for this, is to avoid calling multiple ifs and else ifs checking for multiple different inputs, and instead use that method and place it into a match check for what input that is.
I'll use the example I used on the thread again showcasing how input checking works right now:
func _input(event: InputEvent) -> void: if (event.is_action("MoveForward")): Move(0, 1) elif (event.is_action("MoveBackward")): Move(0, -1) elif (event.is_action("MoveLeft")): Move(-1, 0) elif (event.is_action("MoveRight")): Move(1, 0) elif (event.is_action("Attack")): Attack()
The input above is checked with a if, and a bunch of else ifs checking each different action that the event
is currently performing.
That could have been replaced by a method returning the event action string, which could be checked by a match switch:
func _input(event: InputEvent) -> void: match (event.get_action_type()): "MoveForward": Move(0, 1) "MoveBackward": Move(0, -1) "MoveLeft": Move(-1, 0) "MoveRight": Move(1, 0) "Attack": Attack()
Making input checking handier and better readable.
That's my idea for InputEvent. And yeah, I'm aware that depending on project type, that method of checking input for movement is not good. This is just an example input showing the difference.
Beta Was this translation helpful? Give feedback.
All reactions