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
Support project
Your donation helps me stay engaged in creating valuable projects for Defold. If you appreciate what I’m doing, please consider supporting me!