Dictionary not saving. Not showing up in path or anything...

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

var indices = {"brock": 0, "jayson": 0, "steven": 0, "jodi": 0, "gabe":0, "town": 0, "jaysondoor": 0, "world": 0, "position": global_position}

func increment_index(idx):
	indices[idx] += 1

func _ready():
	pass

func do_save():
	var file: File = File.new()
	file.open("user://saved_game", File.WRITE)
	file.store_var(indices)
	file.close()

func do_load():
	var file : File = File.new()
	if file.file_exists("user://saved_game"):
		file.open("user://saved_game", File.READ)
		indices = file.get_var()
		file.close()

func _input(event):
	if event.is_action_pressed("save_key"):
		do_save()

Doesn’t seem to be saving…

The file isn’t being created, or the file can’t be read?

Ertain | 2022-01-21 04:14

Its not being created.

gummyrat | 2022-01-21 10:36

I think you lose filename extension in your file path in your code.
Like this “user://saved_game.dat” or “user://saved_game.save” rather than “user://saved_game”.
I am not sure but maybe that’s why your file not being created.

ponponyaya | 2022-01-22 05:12

:bust_in_silhouette: Reply From: ramazan

var save_path = “user://data.dat” # for Phone
///var save_path = “C:/Users/****/Desktop/savegame.dat” # for PC
var file = File.new()
var indices = {“brock”: 0, …}

func do_save():
  file.open(save_path, File.WRITE)
  file.store_var(indices)
  file.close()

func do_load():
  var error = file.open(indices, File.READ)
  if error != OK:
  	  do_save()
  error = file.open(indices, File.READ)
  indices = file.get_var()
  file.close()
  return indices