How to save my game on android

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

I’m making a save system to save my game currentlevel progress (for example its saves when I unlocked level 2, and so i dont start over level 1 again).

Im following a tutorial from GDquest https://www.youtube.com/watch?v=IrUhyf-g5hU and it works well on windows when I use const SAVE_PATH = "res://config.cfg".

The problem occur when I debug it to my Android. it just doesnt work. please help, thx
extends Node

const SAVE_PATH = "user://config.cfg"
var _config_file = ConfigFile.new()
var _saved_data = { "current_level" : { "level" : 1 }}

func _ready():
   	load_settings()
	if _saved_data["current_level"]["level"] != _config_file.get_value("current_level","level"):
		_saved_data["current_level"]["level"] = _config_file.get_value("current_level","level")
	set_fixed_process(true)

func save_settings():
	for section in _saved_data.keys():
		for key in _saved_data[section]:
			_config_file.set_value(section, key, _saved_data[section][key])
	_config_file.save(SAVE_PATH)

func load_settings():
	var error = _config_file.load(SAVE_PATH)
	if error != OK:
		print("Failed" % error)
		return[]
	
	for section in _saved_data.keys():
		for key in _saved_data[section]:
			_config_file.get_value(section,key,null)

func _fixed_process(delta):
	if _saved_data["current_level"]["level"] != _config_file.get_value("current_level","level"):
		save_settings()
		print(_saved_data["current_level"]["level"])
:bust_in_silhouette: Reply From: Gerardo Gonzalez

Here in this section is your answer

thanks a lot, I end up using the .json method just like the docs and it works ! I also remove the fixed process. :slight_smile:

with this I conclude that using .json file save method is more reliable for an amateur like me hahaha

ricardohogan | 2018-05-21 04:56

:bust_in_silhouette: Reply From: Gerardo Gonzalez

I saw your code, I have a question: Why are you saving into _fixed_process?

func _fixed_process(delta):
    if _saved_data["current_level"]["level"] != _config_file.get_value("current_level","level"):
        save_settings()
        print(_saved_data["current_level"]["level"])

For me it’s more easy you implement a singleton script and save just calling a fuction to save, then it’s more easy into a singleton script to call a load function to load all your values :-P. Avoid use _fixed_process.

Let me know if this works for you.