#Who can explain to me how to save?
1 messages · Page 1 of 1 (latest)
What exactly do you mean by saving?
As in saving your progress of your project, you just press cntr s.
But pls let me know what you mean by “save”
sorry, I'll try to explain now, I need 3 settings (fullscreen, volume, volume) to be saved when closing the settings menu, I tried to do this but I'm only now creating a file where it says de default value, I did it through a global script in startup, I registered it, but after creating a file with default values, I couldn’t do anything further, could you help me how to do this?
Could you post the script you have right now? @glacial widget
Can’t you just have a variable that holds all these changes settings and use them as the main setting?
Typically this is done by writing settings to a file and reading it on startup. Usually a JSON format is used in this file and it looks something like this
"settings": {
"volume": 1.0,
"fullscreen" true
}
etc. You write to this file as the user hits save in settings and you keep the data in-memory. When the user quits the game, the file remains, so when they open it again, you read the same settings into memory again
You might also be able to write to a resource directly in Godot at runtime also? I'm not sure if that's supported
JSON? I have .cfg
and what do you mean by "resources"?
Ah, sorry I wasn't familiar with .cfg - it seems to do the same thing as JSON at the end of the day. You even have good documentation here: https://docs.godotengine.org/en/stable/classes/class_configfile.html
Inherits: RefCounted< Object Helper class to handle INI-style files. Description: This helper class can be used to store Variant values on the filesystem using INI-style formatting. The stored v...
Good luck, should be quite simple 👍
In short, I didn't figure anything out
What are you struggling with?
Do you not understand it or are you having some issues?
rather, I don’t understand how I can read configurations, or even saves, while I just have a file created
extends Node
var config: ConfigFile
var patch_save := "user://game.cfg"
var section := "setting"
var sound = 1.0
var music = 1.0
var fullscreen = false
func _ready():
config = ConfigFile.new()
var err = config.load(patch_save)
if err != OK:
print("Создаём новый конфиг с дефолтными значениями")
music = 1.0
fullscreen = false
save_game()
else:
load_game()
func save_game():
config.set_value(section, "sound", sound)
config.set_value(section, "music", music)
config.set_value(section, "fullscreen", fullscreen)
var err = config.save(patch_save)
if err != OK:
print("Ошибка при сохранении конфига:", err)
else:
print("Конфиг сохранён по пути:", patch_save)
func load_game():
sound = config.get_value(section, "sound", 1.0)
music = config.get_value(section, "music", 1.0)
fullscreen = config.get_value(section, "fullscreen", false)
print("Конфиг загружен:", patch_save)
I understand that save_game needs to be done in another script if I want it to be saved when clicked
for now I at least need to do it with fullscreen
what do you think?
The code looks correct? What is your issue here?
You need to allow the player to change ‘fullscreen’ via some UI ofc
well fullscreen really should change through the user interface in the game it changes but in the save file it doesn't change, even if I change the value directly in the file it won't be reflected in the game
now I can't create a file at all
I've been trying to do this for about a whole day now but it just doesn't work