Page 1 of 1
Access saver data from Lua
Posted: Mon Mar 09, 2020 8:55 pm
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.
Re: Access saver data from Lua
Posted: Mon Mar 09, 2020 10:15 pm
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;
}
Re: Access saver data from Lua
Posted: Mon Mar 09, 2020 10:40 pm
by VoodooDetective
Ah ok that makes good sense. Thanks!