First, a little tip: All these var brock_index
/ update_brock_index
pairs could be covered with a single dict and a single method. Something like this:
var indices = {"Brock": 0, "Jaysen": 0, "etc": 0}
func increment_index(idx):
indices[idx] += 1
It's just more concise. You don't need update_data
or the second dict game_data
either.
Honestly, I wouldn't use json, it's a headache. You can just save the variable like this:
func do_save(data, path):
var file: File = File.new()
file.open(path, File.WRITE)
file.store_var(data)
file.close()
func do_load(path):
var file : File = File.new()
if file.file_exists(path):
file.open(path, File.READ)
indices = file.get_var()
file.close()
_physics_process
is called 60 times a second and saving is slooooow. So, let's do this instead:
func _input(event):
if event.is_action_pressed("save_key"):
do_save(indices, "res://saved_game/game.dat")
Obviously you need to call increment_index("Brock")
for the value to change before you save.
Hope it put you on the right lines.