#Hello! Trouble with config file

11 messages · Page 1 of 1 (latest)

loud siren
#

How can i convert from strings to InputEventKey my inputs in config file?
They are stored like this Melee=["Q (Physical) 0 81"]

My config input file looks like

ui_filedialog_up_one_level=["Backspace 4194308 0"]
ui_filedialog_refresh=["F5 4194336 0"]
ui_filedialog_show_hidden=["H 72 0"]
ui_swap_input_direction=["Ctrl+QuoteLeft 96 0"]
Jump=["Space (Physical) 0 32", "Z 90 90"]
Melee=["Q (Physical) 0 81"]
Attack=[]```

I am loading it like this: 

            ```swift
var config_file: ConfigFile = ConfigFile.new()
var err: Error = config_file.load(return_config_path(config_name))
            if err != OK:
                var actions = InputMap.get_actions()
                save_config(config_name,actions)
                return actions
            elif new_actions != null:
                save_config(config_name,new_actions)
                return new_actions
            else:
                var section = config_file.get_sections()
                var actions = config_file.get_section_keys(section[0])
                for action in actions:
                    InputMap.action_erase_events(action)
                    var input_actions =  config_file.get_value(section[0],action)
                    for input_action in input_actions:
                        InputMap.action_add_event(action, input_action) # TODO HERE
                return actions```

input_action looks like Enter 4194309 0
How do i resolve it from here?
kind summit
#

@loud siren I have a custom script setup that I can share with you, but I'm not at com right now... I think your next step is parsing the event and passing it in that way.

loud siren
#

Yeah, kinda figured out, but i think i will try to re do this with resources

#

Probably inputmap can be put in to resource

kind summit
#

Did you want to see my script? The save is done through a dictionary, but saved for the game as a part of the resource save.

loud siren
#

Yeah, i wanna see it, thanks

kind summit
#

When the game is first loaded...

func _init_dict(savedDict: Dictionary):
    if !savedDict.is_empty():
        eventChangedDict = savedDict["EventActionKeys"]
        musicVolume = savedDict["MusicVolume"]
        soundVolume = savedDict["SoundVolume"]
        musicOn = savedDict["MusicOn"]
        soundOn = savedDict["SoundOn"]
        $OptionsControl/ComputerControls/UpGrid/Key_Up.text = OS.get_keycode_string(eventChangedDict["ui_up"])
        $OptionsControl/ComputerControls/DownGrid/Key_Down.text = OS.get_keycode_string(eventChangedDict["ui_down"])
        $OptionsControl/ComputerControls/LeftGrid/Key_Left.text = OS.get_keycode_string(eventChangedDict["ui_left"])
        $OptionsControl/ComputerControls/RightGrid/Key_Right.text = OS.get_keycode_string(eventChangedDict["ui_right"])
        $OptionsControl/ComputerControls/SettingsGrid/Key_Settings.text = OS.get_keycode_string(eventChangedDict["ui_settings"])
        $OptionsControl/ComputerControls/BuildGrid/Key_Build.text = OS.get_keycode_string(eventChangedDict["ui_build"])
        $OptionsControl/ComputerControls/DrillGrid/Key_Drill.text = OS.get_keycode_string(eventChangedDict["ui_drill"])
        $OptionsControl/ComputerControls/UpgradeGrid/Key_Upgrade.text = OS.get_keycode_string(eventChangedDict["ui_upgrade"])
        var eventKeyList: Array = eventChangedDict.keys()
        for i in eventChangedDict.size():
            var parseInputKey: InputEventKey = InputEventKey.new()
            parseInputKey.keycode = eventChangedDict[eventKeyList[i]]
            InputMap.action_erase_events(eventKeyList[i])
            InputMap.action_add_event(eventKeyList[i], parseInputKey)
#
var changingEventKeys: bool = false
var eventActionInt: int
var eventActionKey: String
var originalActionKeyArray: Array = [KEY_W, KEY_S, KEY_A, KEY_D, KEY_ESCAPE, KEY_TAB, KEY_SPACE, KEY_U]
var eventChangedDict: Dictionary = {}
#

This is how I change it on the fly.


func _unhandled_input(event):
    if scenePaused:
        return
    if changingEventKeys:
        if event is InputEventKey and event.pressed:
            var setEvent: InputEventKey = event
            for i in eventChangedDict.keys():
                if eventChangedDict.get(i) == setEvent.keycode:
                    changingEventKeys = false
                    return
            eventChangedDict[eventActionKey] = setEvent.keycode
            InputMap.action_erase_events(eventActionKey)
            InputMap.action_add_event(eventActionKey, setEvent)
            changingEventKeys = false
            $OptionsControl/ComputerControls.get_child(eventActionInt).get_child(0).text = OS.get_keycode_string(setEvent.key_label)
        return
#

I do this on my buttons

func _on_key_down_button_up():
    changingEventKeys = true
    eventActionKey = "ui_down"
    eventActionInt = 1
#

Something like that...godot