Saved Game Data

A saved game contains the current state of the dialogue database (e.g., user variables, quest states, which dialogue entries have been visited, etc.) as well as any data that GameObjects have recorded into the Lua environment. The Save System stores saved game data in a string.


What Gets Saved

To keep the saved game data size small, only the following information is recorded from the Lua environment:

Lua Table What's Saved
Actor[] All data
Item[] Only State, Entry_[1,2,3...]_State, and Track (for the Quest System), unless PersistentDataManager.includeAllItemData has been set to true
Location[] Nothing
Variable[] Current value of each variable
Conversation[] SimStatus (whether each dialogue entry has been offered or displayed) unless PersistentDataManager.includeSimStatus has been set to false
Relationships/statuses See the status and relationship Chat Mapper Functions

If you want to capture specific data in your saved game, make sure it's recorded in one of the fields listed above. For example, the UFPS and Realistic FPS integration scripts use the Variable[] and Actor[] tables, which are always included in the saved game.


How To Save Additional Data

There are two ways to save additional data:

  1. Add a persistent data component to a GameObject, or
  2. Assign a delegate method to PersistentDataManager.GetCustomSaveData

Persistent Data Components

Persistent data components record additional data in the Lua environment.

GetCustomSaveData Delegate

You can also write a delegate method and assign it to PersistentDataManager.GetCustomSaveData. The method should return a string containing Lua code to run when reloading the game. See the Saving Custom Data (Inventory Table) recipe for a detailed example with code.

For a simple example, say you want to save a Lua variable highScore that's not in the Variable[] table.

You can do this:

PersistentDataManager.GetCustomSaveData = GetMySaveData;
string GetMySaveData() {
return "highScore=" + Lua.Run("return highScore").AsInt + ";";
}

This will return a string that looks something like:

highScore=42;

This will get added to the saved game string. When the Dialogue System restores a saved game, it simply runs the Lua code in the saved game string.

You can get even fancier by registering C# functions with Lua and adding calls to them in your GetCustomSaveData method. This allows you to run C# functions when loading a game.


<< How to Set Up the Save System | Persistent Data Components >>