Problems with config file

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

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

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.

Zylann | 2020-02-26 01:45

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

var filepath = “user://keybinds.ini”

I use mac

Nitsuga | 2020-02-26 02:55

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.

Magso | 2020-02-26 03:19

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

Nitsuga | 2020-02-26 03:27

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?

Bernard Cloutier | 2020-02-26 13:37

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
@GlobalScope — Godot Engine (3.2) documentation in English

Zylann | 2020-02-26 14:01

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

Nitsuga | 2020-02-26 17:22

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

Nitsuga | 2020-02-26 17:39

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

Zylann | 2020-02-26 18:41

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

Nitsuga | 2020-02-26 21:11