0 votes

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"])
in Engine by (39 points)

2 Answers

+1 vote
Best answer
by (178 points)
selected by

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

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

+1 vote

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

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 fixedprocess.

Let me know if this works for you.

by (178 points)
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.