Topic was automatically imported from the old Question2Answer platform.
Asked By
9BitStrider
I’m using the Input Mapping example to save and load buttons. But I’m having trouble saving values for gamepads.
func load_config():
var config = ConfigFile.new()
var err = config.load(CONFIG_FILE)
if err: #Assuming that options.cfg doesn't exist.
for action_name in INPUT_ACTIONS:
var action_list = InputMap.get_action_list(action_name)
#Since there are two control types, get data for both.
var keyboard = OS.get_scancode_string(action_list[0].scancode)
var gamepad = OS.get_scancode_string(action_list[1].scancode)
config.set_value('input', action_name, keyboard)
config.set_value('input', action_name, gamepad)
config.save(CONFIG_FILE)
Using the above gives me an error “Invalid get index ‘scancode’ (on base: ‘InputEventJoyButton’)”
Read up about this in the docs, but can’t quite to get it working. Saving keyboard keys works just fine.
var gamepad = Input.get_joy_axis_string(action_list[1].axis)
Thank you. That worked perfectly.
9BitStrider | 2019-06-16 12:54
Interesting. The config file actually spells out the name of the key. (IE: Apostrophe) Is there a function that spits out the symbol by chance or do I need to code that myself? I’m asking due to the limited amount of space for text on my options screen.
9BitStrider | 2019-06-16 15:09
You can implement a simple shortening function:
const DICT = {
'Apostrophe': "'",
}
func shorten(key):
return DICT[key] if key in DICT else key
Just call this shorten function after getting the string from Input: