Access saver data from Lua

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Access saver data from Lua

Post by VoodooDetective »

Is it possible to access a saver's data from Lua? I'm wondering if I should have each object's state saved with a saver, or use lua variables for state that needs to be accessed from lua.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Access saver data from Lua

Post by Tony Li »

Generally speaking, a saver's data is only updated when saving the game or changing scenes. If that's fine for your needs, you can write a C# function to get the data, and then register that function with Lua. Here's an example of getting the saved value of an ActiveSaver:

Code: Select all

bool IsActiveSaverActive(string key)
{
    string serializedData = PixelCrushers.SaveSystem.savedGameData.GetData(key);
    return PixelCrushers.SaveSystem.Deserialize<ActiveSaver.Data>(serializedData).active;
}
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: Access saver data from Lua

Post by VoodooDetective »

Ah ok that makes good sense. Thanks!
Post Reply