Page 1 of 1

Linking external conversations from other databases

Posted: Fri Jun 24, 2016 8:46 am
by Ders
Here I am again with another question. This one is a little hard to explain but I'll do my best.

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);
    }
First of all, I can't see those in the editor while the game is running. (I don't know if this is normal or not)
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));
    }
I feel like this is a problem with the link between the multiple databases but I can't figure out what to change to make it work properly. I hope this explanation is clear. Let me know if you need more information about the custom code that should handle this

Re: Linking external conversations from other databases

Posted: Fri Jun 24, 2016 12:07 pm
by bohnstudios
Hi Ders, I don't have Tony's knowledge, but I'm sure Tony knows how to do what you need. It might be longer than usual until he gets back to you. Just a heads up, he's getting ready for a flight for a rare, but much needed holiday....the guy works harder than anybody I know and I'm actually relieved that he's doing it :) Thank you in advance for your kind understanding and patience :) - Ron

Re: Linking external conversations from other databases

Posted: Fri Jun 24, 2016 12:38 pm
by Tony Li
Hi,

The Dialogue Editor has a few limitations:
  • Since it only looks at one database at a time, it can't show detailed information about links to other databases.
  • It edits asset files, so you can't use it to view databases that you've only created in memory.
However, there's a way around the second limitation. Create a dialogue database asset file and add your runtime conversations to it. Then you can view it in the Dialogue Editor. To select your newly-created conversation, you may need to close and open the Dialogue Editor to get it to recognize the new conversation title.

Here's an example scene exported from Unity 5.3.4:

TestRuntimeDatabase_2016-06-24.unitypackage

It has three buttons:
  • Premade Conv: Plays a premade conversation from the database asset file "Premade Database".
  • Runtime DB+Conv: Creates a database in memory, creates a conversation in the database that links to the premade database's conversation, and plays it. You won't be able to view this conversation in the Dialogue Editor.
  • Runtime Conv: Creates a conversation and adds it to the existing database asset file "Runtime Database". You can view this conversation in the Dialogue Editor.
I also left the Dialogue Manager's Debug Level to set Info. This is another way to trace through a conversation, including runtime-generated conversations and databases. Look for lines like:

Code: Select all

Dialogue System: Add Link (actor): ID=#:# 'Dialogue text.'
Dialogue System: Block on False Link (actor): ID=#:# 'Dialogue text.'
(The first line indicates that a follow-up node's Conditions are true; the second line indicates that Conditions are false.)

and

Code: Select all

Dialogue System: actor says 'Dialogue text.'
This appears when an actor actually follows a node.

Re: Linking external conversations from other databases

Posted: Tue Jun 28, 2016 4:14 am
by Ders
Hi Tony,

I've tried your package an noticed that most of our code seems to match. I'm still not really sure why my code in my original project works without errors, but the options don't show up in the UI. The only difference with our code is that I copy a premade conversation from the premade database and make edits to that and then save it to the runtime database. (That is the main difference I can find at least)

EDIT: I tried it with a newly created conversation instead of copying another one and it still doesn't show the options I added at runtime

Ders

Re: Linking external conversations from other databases

Posted: Tue Jun 28, 2016 5:54 am
by Tony Li
Does the example scene in my post above work correctly in your project?

Could it have something to do with conversation IDs? Since my example was very simple, I just hard coded the IDs.

Please feel free to send me an example unitypackage or project. I'm traveling this week, but I'll be happy to take a look at it when I return to the office on Saturday, 2nd July.

Re: Linking external conversations from other databases

Posted: Tue Jun 28, 2016 5:59 am
by Ders
It seems to yes. The things that it describes are also the output (also got no errors).
I set the conversation ID of the runtime conversation like this:

Code: Select all

DialogueManager.DatabaseManager.DefaultDatabase.conversations.Max(x => x.id) + 1
Writing this I'm wondering, could this be the problem? What if the Max() method doesn't take the other databases into account? That way all new conversations would have the same ID.

Assuming this works though, when I want to find an external conversation that is given by title it looks like this:

Code: Select all

Conversation externalConversation = DialogueManager.DatabaseManager.DefaultDatabase.conversations.Find(x => x.Title == externalConversationTitle);
This is where I see it going wrong since we're cross-referencing between multiple databases but I don't check for any errors and this seems to work just fine.

Re: Linking external conversations from other databases

Posted: Tue Jun 28, 2016 3:00 pm
by Tony Li
Instead of DialogueManager.DatabaseManager.DefaultDatabase (which refers only to the Initial Database set on the Dialogue Manager), try using DialogueManager.MasterDatabase. This refers to the total of all loaded databases.