luxeengine / support

A place for users to get help, ask questions, and discuss luxe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Save data

owyoow opened this issue · comments

Hi, I just started using Luxe and so far it's great but I'm having trouble finding how to save data in my game. I'm building a game for iOS at the moment. Is there a way to save data to the document directory?

commented

Hi! Yes you can use the Luxe.io.string_save and string_load functions - here's the list of the related ones.

You can create/destroy multiple save slots with this system, and what and how you populate the slots is entirely up to you. You could for instance store the user inventory in slot 0 and their location in slot 1, if there is only one user. You can also reserve slots for settings but ordinarily you'd have one slot per save game.

Since it's key value pairs it lends well to storing stuff as json, which you can convert to string and feed in there using the regular haxe json API. It should be noted that while it stores the data as "strings" - you can store other stuff (like binary files) using Haxe serialization. Basically, you can save anything in there by first converting it to a string representation (in whichever form) on the way in, and convert it back on the way out.

The string save works the same on all targets on the user facing side, and always uses the above linked app_path_prefs location to save them, which amounts to the documents folder on iOS and the usual AppData (windows) or Application Support (mac). On web it uses Local Storage so the platform specific considerations are to be considered sometimes. There is a Luxe.snow.io.string_save_path which for some reason isn't exposed on the luxe API - but easily accessible which will tell you where it saves if you're looking for the files or folder.

The path it picks uses your package and app name inside your project to determine the path, and on native targets uses SDL to handle that, so their documentation may be of interest on top of that.

The files it saves on native are simple files, and this isn't likely to change, so you could conceptually work on top of or with this system to your liking. The file is slightly obfuscated but only to prevent trivial tampering for unaware users, it's not to be considered secure or anything.

And to add: If you're just looking for "what path do I use for saving a file using regular file API's" then you can use the app_path_prefs with haxe.io.Path.join to get a full path.

Let me know if you have specific questions otherwise.

Thanks a lot for the detailed explanation. This is exactly what I was looking for.