The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hello!
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 = {
        "highscore":beststreak
    }
    return save_dict

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

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")
            return
        save_game.open("user://savegame.save", File.READ)

        var current_line = parse_json(save_game.get_line())

        beststreak = current_line["highscore"]
        save_game.close()
Godot version 3.2.2
in Engine by (127 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 (22,674 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:

https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html

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 Frequently asked questions and 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 [email protected] with your username.