A while ago I asked why my Lua data was resetting which can be read here: viewtopic.php?f=3&t=682
Now, this still seems to pose a problem when trying to connect those conversations together.
So I'm using this code now to finalize a runtime conversation and add it to the database:
Code: Select all
public static void FinishEditingConversation(ref Conversation conversation) {
var database = ScriptableObject.CreateInstance<DialogueDatabase>();
database.conversations.Add(conversation);
DialogueManager.AddDatabase(database);
}
Second, when I try to add a link to an external conversation to this current conversation it doesn't throw errors and it seems to find the conversation I want to add but it doesn't reflect this on the conversation when I show it.
So, conversation A gets a link to conversation B at runtime, so that it shows as a player choice to go to that one. But this option isn't shown in the UI and I can't check in the editor if it's actually connecting or not.
This is the code that adds the external conversation (so conversation B in the example)
Code: Select all
public static void AddNewExternalConversation(ref Conversation conversation, string externalConversationTitle, int previousNode, bool isPlayerChoice, string dialogueText, string condition, string script) {
var nodes = conversation.dialogueEntries;
Conversation externalConversation = DialogueManager.DatabaseManager.DefaultDatabase.conversations.Find(x => x.Title == externalConversationTitle);
var id = 1 + conversation.dialogueEntries.Max(existingEntry => existingEntry.id);
DialogueEntry newEntry = template.CreateDialogueEntry(id, conversation.id, "My Title");
newEntry.conversationID = conversation.id;
newEntry.Title = "Empty";
newEntry.DialogueText = dialogueText;
newEntry.conditionsString = condition;
newEntry.userScript = script;
newEntry.ActorID = isPlayerChoice ? 1 : 2;
newEntry.ConversantID = isPlayerChoice ? 2 : 1;
nodes.Add(newEntry);
nodes.Find(x => x.id == newEntry.id).outgoingLinks.Add(new Link(conversation.id, newEntry.id, externalConversation.id, 0));
nodes[previousNode].outgoingLinks.Add(new Link(conversation.id, previousNode, conversation.id, newEntry.id));
}