0 votes

I am working on a port of my game to Android, I was wondering if anyone knew of a way to save to Android as I could not find a way to find a directory. My problem is that for example on Windows you can call for a file with file_exists("user://savegame.save") If you know of a directory like this for Android please tell me. Thank you!

Here is my code

    func save():
    var save_dict = {
    return save_dict

func save_game():
    if PlayerVars.mobile == false:
        var save_game = File.new()
        save_game.open("user://savegame.save", File.WRITE)

func load_game():
    if PlayerVars.mobile == false:
        var save_game = File.new()
        if not save_game.file_exists("user://savegame.save"):
            print("Error! We Don't Have A Save File To Load")
        save_game.open("user://savegame.save", File.READ)

        var current_line = parse_json(save_game.get_line())

        beststreak = current_line["highscore"]
Godot version 3.2.2
in Engine by (126 points)
edited by

1 Answer

0 votes

Have you tried what you have on Android? That exact same file name should work fine on Android.

by (10,914 points)

I have tried it, I was looking the place where to save it rather than a file name. Or am I misunderstanding you?

The user:// path resolves to an appropriate location for each OS. So, I'm just saying that it's perfectly fine (and expected) that you would use user:// for both Windows and Android (for example): So, your above constructed file path should be perfectly fine for both.

There's some general info here:


The above page mentions:

On some devices (for example, mobile and consoles), this path is unique to the project.

Also, I only have one persistence class and I use it for both Android and Windows. It doesn't contain any OS-specific checks - the exact same code is used for both. My save file name is defined as follows:

var persistFile = "user://savedata.txt"

Thank you for helping!
I am still having problems with it but I can't get data on what is happening so until I can get more information I simply have to work on the problem. Again Thank you.

as it turns out it a single wav file I had added early this morning was the problem... not the saving script -_-

Thank you for helping me with my perceived issue

Yeah, sorry I don't have much more to offer. Your code looks reasonable and the file reference you're using should be fine.

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.