Page 1 of 2

Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 1:29 am
by fkkcloud
Hello,

Is it possible to access persistent data without running the game?

For instance, I want to save/load states while in Editor without playing the session.

Code: Select all

saveObject.dialogueSystemSave = PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData( saveData.dialogueSystemSave );
Also, where can I manually set/see the persistent data?

Thank you

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 8:50 am
by Tony Li
Hi,

Are you using the Dialogue System's save system? If so, then it depends on which saved game data storer you're using. Here's an example of using PlayerPrefsSavedGameDataStorer and JsonDataSerializer:

Code: Select all

var storer = FindObjectOfType<PlayerPrefsSavedGameDataStorer>();
var playerPrefsKey = storer.GetPlayerPrefsKey(slotNumber);
var rawData = PlayerPrefs.GetString(playerPrefsKey);
var savedGameData = JsonUtility.FromJson<SavedGameData>(rawData);

Debug.Log("Game was saved in scene: " + savedGameData.sceneName);

var rawPositionData = savedGameData.GetData("PlayerPosition");
var positionData = JsonUtility.FromJson<PositionSaver.PositionData>(rawPositionData);
Debug.Log("Player position: " + positionData.position);

If you're not using the save system, and if you're only using PersistentDataManager.GetSaveData(), then this function only returns a string. It's up to you to do something with the string. The string is Lua code, so you can print it out to see what it contains. Or you can create a Lua object at runtime and run it through that.

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 12:49 pm
by fkkcloud
Hello,

Yes, I am not using Save System. The part I am asking is...
If I call this function in Editor (while not playing)

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();
It throws an error.
화면 캡처 2021-01-15 094738.png
화면 캡처 2021-01-15 094738.png (88.03 KiB) Viewed 623 times
If I run the code while playing it does not.
I just want to call these 2 functions without playing the session.

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData();

Code: Select all

PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData( saveData.dialogueSystemSave );

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 12:55 pm
by Tony Li
Hi,

If the game isn't running, then there is no save data to get. So PersistentDataManager.GetSaveData() won't work.

What do you want to accomplish?

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 1:40 pm
by fkkcloud
I want to go into save state A from B sometimes just for debug purposes.

Like switching datasets in Scriptable Objects

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 1:45 pm
by Tony Li
What if you use PersistentDataManager.GetSaveData() during play to record a state. Then save this string somewhere, such as in EditorPrefs or PlayerPrefs.

Add another script that can retrieve this string and apply it using PersistentDataManager.ApplySaveData() during play.

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 2:16 pm
by fkkcloud
Maybe I should do that.

Besides that, if I want to set some value manually- where do I want to go?

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 2:23 pm
by Tony Li
Here are ways to set a Lua value manually:
  • Use the "Run" field at the bottom of the Dialogue Editor's Watches panel.
  • Add a Lua Console to your scene. Press ~+L to open it during play. Then enter Lua code. To view a value, use "return". Example:

    Code: Select all

    Variable["x"] = 42
    return Variable["x"]
    Unlike the Dialogue Editor window, you can use a Lua Console in a build. You can also register your own C# methods as Lua functions and call them in the Lua Console.
  • In a C# script, use DialogueLua.SetVariable:

    Code: Select all

    DialogueLua.SetVariable("x", 42);

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 2:37 pm
by fkkcloud
Oh thank you,

and is there any UI as well?
like seeing the list of data in one place? and edit them there? (while not running the game)

Re: Accessing persistent data without running the game

Posted: Fri Jan 15, 2021 2:47 pm
by Tony Li
The save data is Lua code. You can look at it in a text editor. It will look similar to:

Code: Select all

Variable = { Alert = "", x = 42 }; Actor["Player"] = { Name = "Player", IsPlayer = true } ...