Save data
What can it do
Section titled “What can it do”- Save key/values for you
- Save files and arbitrary data for you
- Query data, state and existence of data or slots
- Handle save slots for different users
- Handle cross platform data management
Using the save system
Section titled “Using the save system”First step, import it!
import "luxe: save" for SaveCreate a Save system instance
Section titled “Create a Save system instance”Game data storage locations
Section titled “Game data storage locations”The save system will be able to save the data you ask it to in a good place for the platform your game is running on.
This is different for each platform, but not something you typically have to think about when using Save.
The important thing is that we need to know a little bit of information about your game to store the data in the right spot. This includes the “organization” making the game (could be your name, your studio name, etc), and the game name.
Creating the save system
Section titled “Creating the save system”// create a new save system to use// loads the default save slot for single savesvar save = Save.create("organization", "game")Creating the save system with unique user ID
Section titled “Creating the save system with unique user ID”If you have a unique user ID (for example on Steam, different steam profiles on the same PC will want their own save slots).
Save.create("organization", "game", user_id)Save a simple key/value pair
Section titled “Save a simple key/value pair”Say we want to remember the user setting like “camera fov”. We can use the simple key value store:
Save.set(save, "camera fov", "90")We can also store data at the user level, instead of at the save slot level. For something like a camera setting, the user probably intended to have the same FOV across each save slot. It will be up to you to think about the use cases!
Save.set(save, "camera fov", "90", SaveScope.user)Load a value from key value store
Section titled “Load a value from key value store”When you load values from a save, you have to specify a default value for when the save doesn’t have the data. You can also specify the scope like before
//Get some values from the slotvar name = Save.get(save, "name", "default_name")//get user values, like settingsvar setting = Save.get(save, "camera fov", "90", SaveScope.user)Saving file data
Section titled “Saving file data”You can also save files to the save slot or the user data.
// Instead of doing key values as strings, we can store a Wren mapvar settings = { "play time": 25602}
Save.set_file(save, "settings", LX.stringify(settings))
// Another example, save a screenshot the savevar screenshot_data = ...Save.set_file(save, "screenshot", screenshot_data)Another common case is serializing blocks, for example modifier data, custom blocks and more can be serialized as lx (json like) or binary data.
The save system doesn’t really care what kind of data you’re storing! It just treats it as opaque data.
Loading file data
Section titled “Loading file data”var data = Save.get_file(save, "settings")//settings is now our wren map againvar settings = LX.parse(data)There’s more in the API
Section titled “There’s more in the API”Visit the API documentation for more details!