Defold Saver - Defold Save File Manager

logo

Saver

Saver - is a library for saving and loading save data in Defold projects. It provides a simple API for saving and loading save data, as well as support for migrations and simple key-value storage. The library supports saving and loading data in JSON, Lua, or binary format, and can save and load files to and from the file system.

Features

  • Save and Load Game State: Save and load data with a simple API.
  • File Management: Save and load data to and from files.
  • Auto-Save: Automatically save data at regular intervals.
  • Migrations: Apply migrations to data when the migration version changed.
  • Storage: Store key-value pairs in the save data.
  • Format support: Save and load data in JSON, Lua or binary format.

Setup

See the Defold Saver repository on Github for the Setup, Documentation, API Reference and Use Cases

Basic Usage

The Saver provides a simple API to bind your Lua tables to the save file. This allows you to set up the Saver only once and continue using the state data as usual.

local saver = require("saver.saver")

local game_data = {
	score = 0,
	level = 1,
}

function init(self)
	saver.init()
	saver.bind_save_state("game", game_data)

	-- Now we can change game_data content and it will be saved automatically via autosave
	game_data.score = game_data.score + 1

	-- Or you can save it manually by saver.save_game_state() if you want to save it immediately
	saver.save_game_state()
end

:heart: Support project :heart:

Your donation helps me stay engaged in creating valuable projects for Defold. If you appreciate what I’m doing, please consider supporting me!

Github-sponsors Ko-Fi BuyMeACoffee

22 Likes

Very fast powerful extension - you can specify a table with game data once and by calling just one function it will be saved, which would be automatically loaded the next time you open it. No additional methods like saver.set or saver.get. Once set up and everything works automatically.

3 Likes

I want to tell about saver.get_current_game_project_folder() method ( API / Source ). It returns the current project folder where the game.project file is located. This method only works when the game is launched from the editor.

Often, you might include custom_resources in your game to load data using sys.load_resource(). These could be game levels, configurations, or settings. However, these files are included in the build before launching the game, and if you change them, you need to restart the game.

With this method, you can get the absolute path to your project folder and load files directly from the disk (only if the game is launched from the editor!).

For example, this is how “hot reload” works in Panthera (example here), or you can create a custom level editor and modify it directly from the game! Previously, I used usual file saving for this :upside_down_face:

3 Likes