I tried it, but unfortunately it isn't working in our project. I tried your original script, which causes some errors. I then did the following:
Firstly, I commented out the Articy ID part, because that doesn't really need to be saved. I just used it as a key previously. Also, the name of the varibable is not ArticyId but 'Articy Id' which caused issues in the Lua script. But since it's not needed:
Code: Select all
private IEnumerator Start()
{
// Let Dialogue Manager load database first:
yield return new WaitForEndOfFrame();
// Then add in the custom Dialog values:
foreach (var conversation in DialogueManager.MasterDatabase.conversations)
{
var sb = new StringBuilder();
sb.AppendFormat("Conversation[{0}].Dialog = {{", conversation.id);
foreach (var entry in conversation.dialogueEntries)
{
//var articyId = Field.LookupValue(entry.fields, "ArticyId");
var currentValue = Field.LookupInt(entry.fields, "CurrentValue");
//sb.AppendFormat("[{0}] = {{ ArticyId = '{1}', CurrentValue = {2} }}, ", entry.id, articyId, currentValue);
sb.AppendFormat("[{0}] = {{ CurrentValue = '{1}' }}, ", entry.id, currentValue);
}
sb.Append("}; ");
Lua.Run(sb.ToString(), true);
}
}
Am I right that the whole part in Start() is only needed when the values in *new* games are not all 0? If so, we wouldn't even need this whole method at all.
In GetMyCustomSaveData, I tried both the code you wrote for this and when it wasn't working properly in the project, also the stolen code from the Sim Status stuff in the PersistantData manager which looks like it's doing the same thing in a slightly different way.
The problem with the original code from this forum post was that I got an error saying it couldn't cast the variable in this line:
var currentValueNumber = (System.Single)dialogValueTable["CurrentValue"];
I then changed that into casting that into a string and then just use that string in the Lua script (see below).
When that didn't work out, I tried the stolen code from the PersistantDataManager you use for storing the Sim Status. It's commented out in the code snippet below.
Code: Select all
private string GetMyCustomSaveData()
{
var sb = new StringBuilder();
foreach (var conversation in DialogueManager.MasterDatabase.conversations)
{
//Debug.Log("<color=red>Conv: " + conversation.id + "</color>");
sb.AppendFormat("Conversation[{0}].Dialog = {{ ", conversation.id);
// From forum:
var dialogTable = Lua.Run("return Conversation[" + conversation.id + "].Dialog").AsTable;
foreach (var key in dialogTable.Keys)
{
var dialogValueTable = dialogTable[key] as LuaTableWrapper;
//var currentValueNumber = (System.Single)dialogValueTable["CurrentValue"];
var currentValueNumber = dialogValueTable["CurrentValue"].ToString();
//var currentValue = (int)currentValueNumber;
var currentValue = currentValueNumber;
sb.AppendFormat(" [{0}] = {{ CurrentValue = {1} }}, ", key, currentValue);
}
/*
// From sim status code:
var conversationTable = Lua.Run("return Conversation[" + conversation.id + "]").AsTable;
var dialogTable = conversationTable.luaTable.GetValue("Dialog") as Language.Lua.LuaTable;
for (int i = 0; i < conversation.dialogueEntries.Count; i++)
{
var entryID = conversation.dialogueEntries[i].id;
var dialogFields = dialogTable.GetValue(entryID) as Language.Lua.LuaTable;
if (dialogFields != null)
{
var currentValue = dialogFields.GetValue("CurrentValue");
sb.AppendFormat("[{0}]={{CurrentValue=\"{1}\"}},", new System.Object[] { entryID, currentValue });
}
}*/
sb.Append("}; ");
}
//Debug.Log("<color=red>" + sb.ToString() + "</color>");
return sb.ToString();
}
Both variations didn't really work.
I now suspect AdventureCreator to be the problem. The string which is supposed to be stored in an AC variable becomes SO very long. We have 947 conversations and 591 variables in the database. In these 947 conversations, we have 7435 lines which all have a CurrentValue. It might just be too much / the string getting too long?