0 votes

The fact is that Godot does not load values ​​from the configuration file, whatever I do. I looked through a bunch of lessons and so did not understand what my mistake was. The script saves the value of the variable and stores it in the file, but when it comes to loading the variable, nothing comes out of the file.

    var FPSview = true
var lang = 1
var Volume = 1
const SAVE_PATH = "res://local/config.cfg"
var _config_file = ConfigFile.new()

var _settings = {
    "test" : {
        "fps" : FPSview 
    "lang" : {
        "langset" : lang
func save_settings():
    for section in _settings.keys():
        for key in _settings[section].keys():
            _config_file.set_value(section, key, _settings[section][key])

func load_settings():
    var err = _config_file.load(SAVE_PATH)
    if err != OK:
        # Likely no settings were saved yet
        return err
    for section in _settings.keys():
        for key in _settings[section].keys():
            var val = _settings[section][key]
            _settings[section][key] = _config_file.get_value(section, key, val)
    return OK

func del_settings():
    var dir = Directory.new()

func get_config(section, key):
    return _settings[section][key]

func set_settings(section, key, value):
     _settings[section][key] = value

func _on_Save_pressed():

func _on_fpsOn_pressed():
    _settings.test.fps = true

func _init():
    GlobalSettings.setFPSvw = FPSview
    _settings.test.fps = FPSview 

func _on_fpsOn2_pressed():
    _settings.test.fps = false

I also set the scene as a global singleton and track the variable in the scene to change the visibility of the table with fps

extends Label

func _ready():
    if Settings.FPSview ==  true:
        get_node(".").visible = true
    if Settings.FPSview  == false:
        get_node(".").visible = false

func _process(delta):
    self.text = 'FPS: ' + str(Engine.get_frames_per_second())
in Engine by (71 points)

im not sure with this if err != OK:

1 Answer

0 votes
    func savedata(hs):
        var hs_old=load_data()
        if hs_old<hs:
            var data={

    func load_data():
        if file.file_exists(savePath):
            var dict = {}
            highscore = dict["highscore"]
            var data={
        return highscore

Im using this for save and load high score hope it can help, and try from small data befor implement it in your project

by (48 points)
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 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 webmaster@godotengine.org with your username.