I dont know how to save and load my game

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

I recently started working on a video game, it is platform so it takes many levels, I use global variables to determine if a level is unlocked or not, I need a way to save the information about which levels are unlocked so that when one re-enters to the game the levels that I already have unlocked are still unlocked, I have tried tutorials and documentation, but I still cannot find a solution, I am using this code but whenever I use it it says “No saved data” so I have tried to follow all the steps it takes with print to see if something is wrong somewhere, but from what I have seen it just can’t find the file and I don’t know what to do anyway I don’t know much about programming, only when reading the information it tells me “no saved data”

recientemente comencé a trabajar en un videojuego, es de plataformas así que lleva muchos niveles, uso variables globales para determinar si un nivel esta desbloqueado o no, necesito una manera de guardar la información sobre cuales niveles están desbloqueados para que así cuando uno vuelva a entrar al juego los niveles que ya tenga desbloqueados sigan desbloqueados, he tratado con tutoriales y con la documentación, pero sigo sin lograr una solución, estoy usando este código pero siempre que lo uso me dice “No saved data” así que he tratado de seguir todos los pasos que da con print para ver si en alguna parte falla algo, pero por lo que he visto simplemente no encuentra el archivo y ya no se que hacer igual yo no se mucho de programación , solo que al momento de leer la información me dice “no saved data”

extends Node

const FILE_NAME = “C:/user://game-data.json”

var n1 = NivelCode.nivel1
var n2 = NivelCode.nivel2
var n3 = NivelCode.nivel3
var n4 = NivelCode.nivel4
var n5 = NivelCode.nivel5
var n6 = NivelCode.nivel6
var n7
var n8

func _physics_process(delta):
if Input.is_action_just_pressed(“Guardar”):
save()

if Input.is_action_just_pressed("debug"):
	
	print("player guardado = ", player)
	print("Nivel 1 gloval var = ", NivelCode.nivel1)
	print("n1 = ", n1)

var player = {
“n1” : 0,
“n2” : 0,
“n3” : 0,
“n4” : 0,
“n5” : 0,
“n6” : 0

}

func save():



var file = File.new()
file.open(FILE_NAME, File.WRITE)
print("file open")
file.store_string(to_json(player))
print("store")
file.close()
print("guardado")

func load_game():
var file = File.new()
if file.file_exists(FILE_NAME):
file.open(FILE_NAME, File.READ)
var data = parse_json(file.get_as_text())
file.close()
if typeof(data) == TYPE_DICTIONARY:
print(“data=”, data)
player = data
else:
printerr(“Corrupted data!”)
else:
printerr(“No saved data!”)
print(“Cargando”)
print(“antes del guardado”, player)
NivelCode.nivel1 = n1
NivelCode.nivel2 = n2
NivelCode.nivel3 = n3
NivelCode.nivel4 = n4
NivelCode.nivel5 = n5
NivelCode.nivel6 = n6
player = {
n1 = NivelCode.nivel1,
n2 = NivelCode.nivel2,
n3 = NivelCode.nivel3,
n4 = NivelCode.nivel4,
n5 = NivelCode.nivel5,
n6 = NivelCode.nivel6
}

print("despues de Func cargar")
print("player guardado = ",  player)
print("Nivel 1 gloval var = ",  NivelCode.nivel1)
print("n1 = ", n1)

that’s the code i’m using, i don’t know if someone can guide me or something, i really need help
ese es el codigo que estoy usando, no se si alguien me puede orientar o algo, enserio necesito ayuda