How to save a game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By loloid

Hi,

I’m making a game in gdscript in which i made a save system that work like this :

const filepath = "res://save/lists.save"
func load_list():
	var file = File.new()
	if not file.file_exists(filepath): return
	file.open(filepath, File.READ)
	saved_list = file.get_var()
	file.close()
	pass

func save_list():
	var file = File.new()
	file.open(filepath, File.WRITE)
	file.store_var(saved_list)
	file.close()
	pass

In my file, i store a list of array. This code seems to work if i use it in the engine. But when i’m exporting my game, it doesn’t work anymore. I can use the array that i did in the engine, when i use “save_list()” it works when i’m in the game but as soon as i close the game, “lists.save” return as when i exported the game.

I’m sorry if i’m not clear, i’m not native English speaker so i hope you’ll understand.

loloid

:bust_in_silhouette: Reply From: player0815

iam not sure but i suspect you have to use “user://[filepath]” as path, because thats the only place where you have writing access

than in windows you find this file in %appdata%/godot/[your_project]/