Best way to deal with Loading / Saving

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
andrew2110
Posts: 39
Joined: Wed Sep 03, 2014 2:44 am

Best way to deal with Loading / Saving

Post by andrew2110 »

Am getting very close to being able to wrap up my game now. I'm looking into the best way of loading and saving the Dialogue System state. My save game system works with EasySave and Parse (for cloud stored saved games).



I did have some examples of code for this but then it looked horrendous on here when I tried to copy and paste it, I guess I'm really just asking for an easy way to iterate through all Lua variables.





Edit: I think it's ok to delete this thread now. I'm just going to keep a track of when Lua variables are changing and only store things when they change.
andrew2110
Posts: 39
Joined: Wed Sep 03, 2014 2:44 am

Best way to deal with Loading / Saving

Post by andrew2110 »

Actually, I've been looking for a way to iterate through all quests for a while now and not yet been able to find any way of doing it just yet.



I'll just need to save quests where quest states are not "unassigned" I think. I can see in the assembly browser that there's a way to do this and it's used by the QuestLog classes, but haven't been able to figure this out just yet.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Best way to deal with Loading / Saving

Post by Tony Li »

Hi Andrew,



There happens to be a FAQ specifically on saving the Dialogue System state with Easy Save. If you want to use it, the code would be just one line:

ES2.Save(PersistentDataManager.GetSaveData(), "myFile.txt?tag=dialogueSystem");





To get all quests, call QuestLog.GetAllQuests():

string[] questNames = QuestLog.GetAllQuests(QuestState.Active|QuestState.Success|QuestState.Failure);

Or you can grab the Lua Quest[] table and iterate through it manually. The code below returns a LuaTableWrapper, which is a layer that isolates you from the actual Lua implementation's table.

LuaTableWrapper questTable = Lua.Run("return Quest").AsTable;

foreach (var questName in questTable.Keys) {

LuaTableWrapper quest = questTable[questName] as LuaTableWrapper;

Debug.Log(questName + " state: " + quest[State]);

}








andrew2110
Posts: 39
Joined: Wed Sep 03, 2014 2:44 am

Best way to deal with Loading / Saving

Post by andrew2110 »

Oh thats awesome, so sorry I missed that on the FAQ! Thats perfect
Post Reply