How can i save and load my game?

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

hey guys again,

i have a problem.

this is my actually code:

    extends Node

var points = 0

var store = {
			'bought' : [true, false, false],
			'selected': 0
}
var save_store_path = 'res://save'

func save_store():
	var file = File.new()
	file.open(save_store_path, file.WRITE)
	file.store_var(store)
	file.close()

func load_store():
	var file = File.new()
	if not file.file_exists(save_store_path):
		return false
	file.open(save_store_path, file.READ)
	store = file.get_var()
	file.close()
	return true

and it works.

but when i change from:

var save_store_path = 'res://save'

to:

var save_store_path = 'user://save'

it doesn’t work.
also, when i open my project folder (Godot > Project > Open Project Data Folder) does it take me there:

https://ibb.co/cxss9BG

does anyone knows what i can do?

Could you tell the exact error that you’re seeing ?

devAS | 2021-01-10 13:00

there is no. it just don’t save

felaix | 2021-01-10 15:01

What do you exactly mean by it’s not working; is it not saving the store in save file? Because when I try your code it does not save anything in the file in either location.

devAS | 2021-01-11 12:31

i got it. i just forgot to call the func save & load … xD

felaix | 2021-01-11 13:04

I knew that was the cause but in my case it doesn’t save anything even after calling both funcs in _ready():. But glad you solved your problem. :slight_smile:

devAS | 2021-01-11 13:31