0 votes

Hello

I'm trying to make a key configuration menu with an ini file, I've already seen tutorials where they do it, but for some reason I can't do it.

I don't know much about it, so I hoped you could help me.

This is my script

extends Node

var filepath = "res://keybinds.ini"
var configfile

func _ready():

configfile = ConfigFile.new()

if configfile.load(filepath) == OK:
    for key in configfile.get_section_keys("keybinds"):
        var key_value = configfile.get_value("keybinds", key)
        print(key, ":", key_value)
else:
    print("CONFIG FILE NOT FOUND")

And always print CONFIG FILE NOT FOUND

Thanks for the help

in Engine by (106 points)

Did you try with a path that doesn't start with res://? The doc mentions a path using user:// (which is %AppData%/roaming/godot/yourgame on Windows, and somewhere in your home on Linux I believe).
The reason is files under res:// will not remain as files in an exported game (they will become read-only packed), so it's better to use a cross-platform writable directory to store player's keybindings, such as user://
I'm not sure why it won't load for res://, I thought it would work in the editor.

I don't understand, it should be like that?:

var filepath = "user://keybinds.ini"

I use mac

I'm sure user:// for Mac and Linux are both home/.local/share/godot/your project name. Using user:// allows the game to look in a specific directory no matter which OS it's built for. It basically saves having to know and swap between various file systems.

I tried but still wrong
I don't know what the problem will be

Are you sure the file is under the path res://keybinds.ini and that there is no typo? Could you add a screenshot of the resource folder and paste the content of the ini file?

Are you sure you aren't getting another error in the console when trying to load the file?

Yeah you can check the return value of the load function, it's not necessarily a file error, it could be a syntax error inside it
https://docs.godotengine.org/en/3.2/classes/[email protected]#enum-globalscope-error

this?

print(configfile.load(filepath))

return 19

print(load(filepath))

return [Object:null]

edit:
this error also returns when print(load(filepath)) : No loader found for resource: res://keybinds.ini

This is the content of the ini file for now.

[keybinds]

arriba=87
abajo=83
derecha=68
izquierda=65

I already checked it and everything is well written

the ini file name is keybinds.ini

this error also returns when print(load(filepath)) : No loader found for resource: res://keybinds.ini

This is normal. I didn't mean the global load function, but the load method of ConfigFile.

return 19

This means Can’t open error.

I made a simple test on my end using your config file, and it works fine (I'm on Windows 10).
At this point I think you made a typo, the file is not in the right place, or your OS acts funny, I don't know.
My project: http://zylannprods.fr/dl/godot/qa/IniFile.zip

I download your project moved the ini file to my game and it worked i guess i had something wrong.
Sorry for the inconvenience and thanks for the help

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.