How to handle long/repetitive input map for local multiplayer?

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

I am making a 4-player local co-op game. I have 4 full sets of all of the inputs, each with a suffix representing the player number, i.e. move_up1, move_up2, etc.

Each player has an input action to switch directly to one of 9 weapons, for a total of 36 weapon-related inputs.

Currently what I have started writing is this:

func weapon_action(event):
	if event.is_action_pressed("weapon11"):
		return {"weapon": 1, "player": 1}
	elif event.is_action_pressed("weapon12"):
		return {"weapon": 1, "player": 2}

Is there a good way to get the pressed weapon # and player # without having 36 if…elif branches?

:bust_in_silhouette: Reply From: jgodfrey

You could store the info in a Dictionary and process that instead. So, something like:

var input_info = {
    "weapon11": {"weapon": 1, "player": 1},
    "weapon12": {"weapon": 1, "player": 2},

func weapon_action(event):
    for key in input_info.keys():
        if event.is_action_pressed(key):