Pattern matching for actions and general inputs

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MicroWave

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 _unhandled_input function.

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

:bust_in_silhouette: Reply From: MagnusS

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.