Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | JerryHayat |
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])
_config_file.save(SAVE_PATH)
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()
dir.remove("res://local/config.cfg")
func get_config(section, key):
return _settings[section][key]
func set_settings(section, key, value):
_settings[section][key] = value
func _on_Save_pressed():
save_settings()
load_settings()
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():
#set_process(true)
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())
im not sure with this if err != OK:
wahyuadiramadan | 2020-03-10 18:37