0 votes
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...

in Engine by (25 points)

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

Its not being created.

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.

1 Answer

0 votes
Best answer

var savepath = "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
by (650 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.