Custom idea for user config

Godot Version

Godot 4.4.1

Question

Good evening! It’s my first post here.

I am trying to make use of a dictionary to handle user inputs, in hopes that doing so will make it easier for a player to edit the game’s config file during runtime. However, I keep running into the error:

Invalid type in function ‘is_action_just_pressed’ in base ‘Input’. Cannot convert argument 1 from int to StringName.

I’m attaching pictures of my code, hope it helps! (Note that not_zero.gd is the player character’s node, named such because the project is MegaMan Zero inspired.)

First, I recommend you use InputMap instead of trying to implement your own system for mapping inputs.

Second, Input.is_action_just_pressed takes in a String/StringName as an argument. Constants like KEY_SPACE are not strings but rather ints, so they do not work with that function. Additionally, you’re supposed to add actions to the input map in project settings and use the names of those actions in the input function instead of the actual input itself.

1 Like

I understand, thank you for replying! I just thought I’d try a different method, to allow for custom configs.
I’ll use the InputMap going forward!

The InpuMap does allow for custom configs with add_action and action_add_event, this doesn’t have a great tutorial on the docs page, especially because it’s complex and there are many ways to present remapping controls.

Here’s a sample of how I use these functions, there are still many more parts to it.

### Inside a func _unhandled_input
# Get the previous bound InpuEvent and erase it
var current_event: InputEvent = setting_rebind[current_key]
if current_event:
	InputMap.action_erase_event(action_name, current_event)

# Duplicate the pressed event
var new_event := event.duplicate()

# Add duplicate to action map
InputMap.action_add_event(action_name, new_event)

# Add duplicate to dictionary of rebound controls (so it may be removed later if rebound again)
setting_rebind.set(current_key, new_event)
1 Like