0 votes

I'm currently trying to cut down on the ugly use of if branches in my input handling and tried switching over to pattern matching as it would - at least based on how I'm currently imagining it - provide a way cleaner implementation.

However, I can't find a way to get an action name via the currently pressed button, only the possibility to check for a certain action correspondence which won't work in combination with matching.
Currently getting the input from the unhandledinput function.

Is there a way to manage this or do I have to stick to if-else branching?

in Engine by (12 points)

1 Answer

0 votes

I recommend sticking to if-elif-else structures. I'm not quite sure what you dislike about them but they are the way to go.
Just try to avoid unnecessary nesting and your code looks perfectly fine. When you have 3 ore more nested ifs your usually doing something wrong.

by (330 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.