Skip to content

Save data

  • 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

First step, import it!

import "luxe: save" for Save

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.

// create a new save system to use
// loads the default save slot for single saves
var 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)

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)

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 slot
var name = Save.get(save, "name", "default_name")
//get user values, like settings
var setting = Save.get(save, "camera fov", "90", SaveScope.user)

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 map
var settings = {
"play time": 25602
}
Save.set_file(save, "settings", LX.stringify(settings))
// Another example, save a screenshot the save
var 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.

var data = Save.get_file(save, "settings")
//settings is now our wren map again
var settings = LX.parse(data)

Visit the API documentation for more details!