Defold Persist

Hi all,

Defold Persist provides a simple interface for saving and loading data in a Defold game engine project.

Please note that there are other wonderful modules out there that aim to solve the persistency problem, so feel free to have a look at those as well. Persist mainly focuses on simplicity and ease-of-use. I used this module in Cx6 and will continue to use it in the future.

Happy Defolding!

21 Likes

In the documentation for Persist, I have the following table:

Here are all of the platforms that Defold supports at the moment:

If you have access to any of the platforms that aren’t listed in the documentation (most of them!) then please consider calling persist.save() or simply just:

-- File doesn't have to actually exist.
-- Simply returns the standardized save location as a string.
print(sys.get_save_file("Test App", "settings"))

Then either submitting a pull request or commenting on this thread with the output. I’d like to provide support for all platforms, but I don’t have access to many of them. Thanks!

1 Like

Using the dev app on Android gives me: /data/user/0/com.example.myapp/files/settings

From StackOverflow, the pattern is /data/user[_de]/<user_id>/<pkg>/files, with _de and user_id explained like this:

  • /data/user_de is the Device Encrypted storage on FBE devices which lets certain apps run on boot without asking for user credentials.
  • For multiple users/profiles, <user_id> is different, the device owner is always 0. /data/user/0 is a symlink to /data/data for historical reasons.
1 Like

On Linux, sys.get_save_file() defaults to ~/.{app_name}/{file_name}, e.g. /home/potota/.MyGame/save0. This is not great since it clutters up the user’s home folder. DefSave modifies the app name you give it so that files save to ~/.config/{app_name}/{file_name} instead, like other engines do:

Technically, it should be {config}/{app_name}/{file_name} where config is the environment variable XDG_CONFIG_HOME - defaulting to ~/.config if that’s not set. This is what Unity does, according to their docs.

5 Likes

Thank you, I pushed this feature for Linux!

2 Likes

I added automatic JSON support for files that have the .json extension. This means that you can persist.save() and persist.load() data directly to and from JSON files. Please let me know if you run into any problems.

7 Likes