Change Conversation Fields on Runtime
Posted: Thu Aug 10, 2023 8:10 pm
Hi, I really need help because this is driving me crazy and I'm out of ideas. It's probably something I'm not getting at all, I'm new with Lua so maybe you can help me.
Context is:
I've got a Dialogue Database with a conversation that has a custom field called CurrentStepID = 0; there is a Start node, then 3 child nodes. Each child node has conditions Conversation[1].CurrentStepID == 0, 1 or 2 respectively. At the end of each branch, it increases the CurrentStepID value using the Lua code Conversation[2].CurrentStepID = 1;
The Dialogue Manager (Dialogue System Controller component) has checked 'Allow Only One Instance', 'Don't destroy on Load', and 'Instantiate Database'.
In-game, I trigger via C# script the conversation and it goes through the first branch, and then changes CurrentStepID to 1. If I run the conversation again in the same playing session, it correctly checks the condition and goes through second branch, and so on. So, for the same playing session, it all runs as expected. For the purpose of this error, we'll run the conversation just once, so CurrentStepID = 1.
I've got a custom save system (because reasons) that saves the value of CurrentStepID on a Dictionary<int, int> with key being Conversation ID. It saves correctly.
Now, on the next play session, on game start, I load the saved data that correctly contains the CurrentStepID = 1 for .
I'm trying to load the saved value into the conversation field, to no success, so when triggered in this new play session it starts at the second branch, but it keeps the CurrentStepID = 0 and triggers the first branch.
I think I understand that the database asset is loaded as read-only, and all the changes are made on the instanced database in-memory, but surely I'm missing something cause no matter what I do, CurrentStepID stays with value 0.
Things that I've tried:
In all cases, the conversation triggers with CurrentStepID = 0. I tried these methods before triggering the conversation, and also in the event OnConversationStart, with same results.
I'm triggering the conversation with this code:
I don't know what I'm missing and it's probably something I don't understand about the instancing and the Lua Environment, but I'm kind of desperate now and it baffles me how easy is to get a field value and how apparently impossible is to set it. Any ideas? Thank you in advance!
Context is:
I've got a Dialogue Database with a conversation that has a custom field called CurrentStepID = 0; there is a Start node, then 3 child nodes. Each child node has conditions Conversation[1].CurrentStepID == 0, 1 or 2 respectively. At the end of each branch, it increases the CurrentStepID value using the Lua code Conversation[2].CurrentStepID = 1;
The Dialogue Manager (Dialogue System Controller component) has checked 'Allow Only One Instance', 'Don't destroy on Load', and 'Instantiate Database'.
In-game, I trigger via C# script the conversation and it goes through the first branch, and then changes CurrentStepID to 1. If I run the conversation again in the same playing session, it correctly checks the condition and goes through second branch, and so on. So, for the same playing session, it all runs as expected. For the purpose of this error, we'll run the conversation just once, so CurrentStepID = 1.
I've got a custom save system (because reasons) that saves the value of CurrentStepID on a Dictionary<int, int> with key being Conversation ID. It saves correctly.
Now, on the next play session, on game start, I load the saved data that correctly contains the CurrentStepID = 1 for .
I'm trying to load the saved value into the conversation field, to no success, so when triggered in this new play session it starts at the second branch, but it keeps the CurrentStepID = 0 and triggers the first branch.
I think I understand that the database asset is loaded as read-only, and all the changes are made on the instanced database in-memory, but surely I'm missing something cause no matter what I do, CurrentStepID stays with value 0.
Things that I've tried:
Code: Select all
private void SetFieldsTest()
{
Conversation thisConvo = DialogueManager.MasterDatabase.GetConversation(conversationID);
if (thisConvo != null)
{
//I don't see any effects using this Lua code, it paints the Debug info and no errors are shown, but CurrentStepID stays with value 0.
string luaCode = string.Format("if not Conversation[{0}].{1} then Conversation[{0}].{1} = '{2}' end\n", conversation.id, "CurrentStepID", 1);
luaCode += string.Format("Conversation[{0}].{1} = '{2}'\n", conversation.id, "CurrentStepID", 1);
Lua.Run(luaCode, true, true);
///////
//Same than previous one, executes OK but I can't see any changes at all in the field inside the conversation (checking the Lua environment too)
DialogueLua.SetTableField("Conversation", thisConvo.Title, "CurrentStepID", 1);
//This one changes the value on thisConvo, and you can see the change in the inspector while debugging, but it remains unchanged in the Lua Environment.
thisConvo.fields.Find(x => x.title == "CurrentStepID").value = "1";
//This one gives same result as the previous one, changes the value on thisConvo, and you can see the change in the inspector while debugging, but it remains unchanged in the Lua Environment.
Field.SetValue(thisConvo.fields, "CurrentStepID", 1);
}
}
I'm triggering the conversation with this code:
Code: Select all
Conversation conversation = DialogueManager.masterDatabase.GetConversation(conversationID);
if (conversation != null)
DialogueManager.StartConversation(conversation.Title, transform);