Slots, metadata and backups

Named save slots with their own data and description, rotating backups, and the recovery ladder that completes a damaged save from the newest copy that still works.

Data and safety NexusForge Persistence 1.0.0 Updated

Named slots#

csharp
var slot = Persist.Slots.Create(class="tok-str">"Chapter 1");   // a display name becomes a safe folder name
Persist.Slots.Select(slot.Id);

Persist.Save(class="tok-str">"score", 1500);                    // unchanged code, a different file

Persist.Slots.Select(Persist.Slots.Default);    // back to the built-in slot
CallWhat it does
Persist.Slots.List()every slot, with its state, size, and when it was last written
Persist.Slots.Create(displayName, id)makes a slot; the id is derived from the name unless you give one
Persist.Slots.Select(id, remember)sends later saves to that slot; remember: true survives a restart
Persist.Slots.Inspect(id)the state, the problem in plain words, and the exact code for that problem
Persist.Slots.Rename, Relabel, Delete(confirm: true)renames the folder, changes the shown name, deletes

Each slot lives in its own folder with its own save file, its own backups and a small slot.json description. A description is never a source of truth: every list, load and report reads the save file itself, so a missing or damaged description cannot make a slot look better or worse than it is.

Backups#

Every save keeps the file it replaced. Three copies by default, between one and ten:

csharp
Persist.Backups.Keep = 5;
int howMany = Persist.Backups.Count();
Persist.Backups.Restore(confirm: true);      // puts the newest usable copy in place

The recovery ladder#

When the file a load wants cannot be used, the newest copy that still works is used instead, and the result says which file that was:

csharp
var result = Persist.LastResult;

if (result.Recovered)
{
    Debug.Log(class="tok-str">"Loaded from " + result.RecoveredFrom);   // the full path
    Debug.Log(result.Code);                             // PK-RECOVERY-002, or whatever was wrong
}
CodeWhat it means
PK-INTEGRITY-001The file was changed or damaged after it was written
PK-RECOVERY-001There is no usable backup to go back to
PK-RECOVERY-002The current file was missing, so the newest usable copy was used
PK-FORMAT-001That file is not a PersistKit save, or its format is newer than this build
PK-VERSION-001That save came from a newer build of the game

Nothing is ever deleted or repaired behind your back: a damaged file is left exactly where it is, because it may still hold data the backups do not, and it is the thing somebody would look at to work out what happened.

File management#

Persist.Files.Exists, List, Delete, Rename, Copy and Path cover the rest. Anything that replaces or deletes saved data needs confirm: true.

Next#

Something wrong on this page? Every page here describes behaviour that is checked in the repository. If a page and the package disagree, the package wins.

Report a documentation problem · Error codes · Platforms and limitations