Did I correctly set up my json file?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Myself(Me)

I’m new to saving and loading games. I struggled to follow the documentation for a bit before I found a video that seemed to to work fine.

The project saves and loads as intended in the editor, but not after exporting. I made sure to export the *json as a resource, but I probably failed to set up the save data correctly in the first place.

Can somebody help me find out what I’m doing wrong?

const SaveFile = "user://save_file.save"

var data = {}

func _ready():
	load_data()

func save_data():
	var file = File.new()
	file.open(SaveFile, file.WRITE)
	file.store_var(data)
	file.close()

func load_data():
	var file = File.new()
	
	if not file.file_exists(SaveFile):
		data = {
			"LevelNum" : 0,
			"SpawnList" : []
		}
		save_data()
	
	file.open(SaveFile, File.READ)
	data = file.get_var()
	file.close()

func reset_data():
	data = {
		"LevelNum" : 0,
		"SpawnList" : []
	}
	save_data()
:bust_in_silhouette: Reply From: Ly97

Maybe you should export as *.save instead of *.json, since your save file extension is a “.save”. And I believe that exporting files in the Resource Tab only works when the file is inside your res:// folder, but I’m not sure about that.

Exporting it as .save didn’t work, so I just changed the extension of user://save_file to .json, which did the trick. I didn’t need to save it to my res:// folder, many thanks.

Myself(Me) | 2023-03-26 12:41