How do I save on web?

Godot Version

4.5.1.stable

Question

How do I save on web? I'm using the setup of in the title screen:

extends Control
var quit = 0
var stuff = {
	"main": { "title": Global.title, "level": Global.level},
}
func _ready():
	#unrelated stuff
	var quittest1 = Global.level
	var thing = save.load_all()
	save.save_all(thing)
	Global.level = thing["main"]["level"]
	Global.title = thing["main"]["title"]
	if quittest1 != Global.level:
		quit = 1
	print(Global.level)
	print(Global.title)



and in save.gd:

extends Node

const SAVE_PATH = "user://"
var default = {
	"main": { "title": 0, "level": 0},
}
func save_all(settings: Dictionary):
	var config = ConfigFile.new()
	for section in settings.keys():
		for key in settings[section].keys():
			config.set_value(section, key, settings[section][key])
	config.save(SAVE_PATH)

func load_all() -> Dictionary:
	var config = ConfigFile.new()
	if not FileAccess.file_exists(SAVE_PATH):
		return default
	config.load(SAVE_PATH)
	var loaded_settings = default.duplicate(true)
	for section in default.keys():
		for key in default[section].keys():
			var loaded_value = config.get_value(section, key, default[section][key])
			loaded_settings[section][key] = loaded_value
	return loaded_settings

For some reason its just loading the defaults in my itch.io test? I have no Idea what’s happening here…

Your save path is a directory path, not a file path.

3 Likes

I switched it to user://main.sav and it still loads defaults.