#Who can explain to me how to save?

1 messages · Page 1 of 1 (latest)

glacial widget
#

I just started doing it and I had problems with saving, I watched guides on YouTube but it didn't work out for me very well, I would be very kind if you could help me figure this out

hot timber
glacial widget
rapid bear
#

Could you post the script you have right now? @glacial widget

hot timber
buoyant geyser
#

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

glacial widget
#

and what do you mean by "resources"?

buoyant geyser
#

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

glacial widget
#

oh well, I'll read it now and try it, I'll write if I need help

buoyant geyser
#

Good luck, should be quite simple 👍

glacial widget
buoyant geyser
#

What are you struggling with?

#

Do you not understand it or are you having some issues?

glacial widget
#

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

glacial widget
buoyant geyser
#

The code looks correct? What is your issue here?

#

You need to allow the player to change ‘fullscreen’ via some UI ofc

glacial widget
#

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 workgdlament

buoyant geyser
#

But where is your code that changes the fullscreen?

#

They need to be connected. When the user presses save you need to read their current setting for full screen and apply it