0 votes

My code saves the player's score into a file using ConfigFile class. It works perfectly on Windows but it doesn't on Android. I tried adding the permission to read and write from/to the filesystem on export but it had no effect. Any ideas? Here's the code in case it helps:

func _ready():
 if f.file_exists("user://save.cf"):
    cf.load("user://save.cf")
    get_node("score/best").set_text("Best score: " + str(cf.get_value("scores", "best")))
 else:
    get_node("score/best").set_text("No save file found, creating one")
    cf.save("user://save.cf")
    cf.load("user://save.cf")
 pass

func _notification(what):
 if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
    if f.file_exists("user://save.cf"):
       if cf.has_section("scores"):
          var best_score = cf.get_value("scores", "best")
          if score > best_score:
             cf.set_value("scores", "best", score)
             cf.save("user://save.cf")
       else:
          cf.set_value("scores", "best", score)
          cf.save("user://save.cf")
 pass
in Engine by (195 points)

Try using File.open(..) == OK instead of file_exists(..)

Alternatively you can use Directory.file_exists() rather than File.file_exists(). BTW you don't need those permissions. (Don't need pass at the end of functions either)

edit: ok, I thought the above was true but looking in my code I do use File.file_exists() not Directory, so not sure what your problem is.. I haven't used ConfigFile.

Please log in or register to answer this question.

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.