Can't create variable and databases

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
zarnes
Posts: 7
Joined: Fri Dec 29, 2017 9:36 am

Can't create variable and databases

Post by zarnes »

Hello,

My team and I are creating a web-based dialogue editor which generate XML. The files are then imported into Unity and I'm converting them into a dialogue database, currently I'm using a blank databse and modify it but the objective is to create a new one for each new XML file.
I managed to create conversations, entries and actors, but not variables and databases. Do you have any informations for me ? :)

Thanks !
User avatar
Tony Li
Posts: 20603
Joined: Thu Jul 18, 2013 1:27 pm

Re: Can't create variable and databases

Post by Tony Li »

Hi,

If you can create XML in Chat Mapper format, you can use ChatMapperTools.Load(file).ToDialogueDatabase() to convert XML to a dialogue database. This way you can set up everything in one XML file, and then import it into the Dialogue System in one line. But the catch is that you need to create your XML file in the same format that Chat Mapper generates. (You don't actually need the Chat Mapper software to do this. You just need to create a compatible XML file.)

Otherwise, if you're creating a database manually, the bottom of this post contains example code to create a new database and conversation, and add it to the runtime environment.

To add a new variable to your database:

Code: Select all

var newVariable = new Variable();
newVariable.Name = "My Variable Name";
newVariable.InitialValue = "something";
newVariable.Type = FieldType.Text; // Specify type of data here.
database.variables.Add(newVariable);
(More info: Variable)
zarnes
Posts: 7
Joined: Fri Dec 29, 2017 9:36 am

Re: Can't create variable and databases

Post by zarnes »

Hi and thanks for the response, I created some variable but I can't change the variable Type, it always stay Text type, I tried that :

Code: Select all

Variable var = new Variable();
var.fields = new List<Field>();
var.fields.Add(new Field("Type", FieldType.Number.ToString(), FieldType.Number)); // I tried this because I can only change tha variable name by changing field, otherwise I get a null exception, though I could get similar results but no luck
var.Type = FieldType.Number;
After that, my type is still text
Image

Maybe its a version problem ? I'm in version 1.6.9.

:!: EDIT :
I found the solution by looking at the source code, I have to set the value BEFORE setting its type :)

I just have now to create database, this shouldn't be a problem with your link !

:!: EDIT 2 :
I managed to dynamically create and load a database and a first conversation but I get an error, though everything seems to work fine :
Dialogue System: Lua code 'Dialog = Conversation[0].Dialog' threw exception 'Lookup of field 'Dialog' in the table element failed because the table element itself isn't in the table.'
Image
User avatar
Tony Li
Posts: 20603
Joined: Thu Jul 18, 2013 1:27 pm

Re: Can't create variable and databases

Post by Tony Li »

You're close!

Does your conversation have a unique ID?

Did you add the dialogue database to the runtime environment using DialogueManager.AddDatabase()? This loads the database into the Lua environment.
zarnes
Posts: 7
Joined: Fri Dec 29, 2017 9:36 am

Re: Can't create variable and databases

Post by zarnes »

My conversation have an id and it's my single conversation, does ids are shared with dialogue entries or something maybe ?
I also added database.

Nothing has changed, I can still play the dialogue without apparent problem but I still have the error. For now it's not really a problem but who knows, a friday afternoon it could become problematic :D

Image
User avatar
Tony Li
Posts: 20603
Joined: Thu Jul 18, 2013 1:27 pm

Re: Can't create variable and databases

Post by Tony Li »

Hi,

Please temporarily set the Dialogue Manager's Debug Level to Info. Then play the scene and get to the point where it has added your new database.

At this point, the Unity editor's Console window should show several Lua statements. One of them should look similar to this:

Code: Select all

Dialogue System: Lua(Conversation[1] = { Status = "", Title = "Conv_1", ..., Dialog = {} };
This line shows that the conversation with ID 1 is being added to Lua. Do you see a line like this for your conversation?
zarnes
Posts: 7
Joined: Fri Dec 29, 2017 9:36 am

Re: Can't create variable and databases

Post by zarnes »

Ok I have the logs, I see the line but it appear twice (last line of logs) :
Image
(bigger version : http://www.casimages.com/i/180103051008248546.png.html)

First I though I was adding the conversation twice in my code. By commenting my Addconversation line, it removed the error, but it also removed the conversation, from the database. I checked if the function which add the conversation is not called twice with breakpoint, but only 1 call.

:!: Edit : I just noticed something strange, on my screenshot there isn't the error, I thought it was due to info parameter but now when I retry it has the error, haha ! I didn't change anything.
Image
http://www.casimages.com/i/18010305320628961.png.html

The error and the second line disapear when I comment the DialogueManager.StartConversation() line.
I'll search in the code to see if I can find the reason I have this error.
User avatar
Tony Li
Posts: 20603
Joined: Thu Jul 18, 2013 1:27 pm

Re: Can't create variable and databases

Post by Tony Li »

Hi,

Each dialogue entry has a reference to its conversation ID. In your example, it looks like the dialogue entry's conversationID isn't set, so its value is 0.

I recommend using the Template class to create conversations and dialogue entries, since it will help make sure all IDs are assigned:

Code: Select all

// Create database:
var database = ScriptableObject.CreateInstance<DialogueDatabase>();

// Create a template, which provides helper methods for creating database content:
var template = Template.FromDefault();

// Create actors:
int playerID = 1;
int npcID = 2;
database.actors.Add(template.CreateActor(playerID, "Player", true));
database.actors.Add(template.CreateActor(npcID, "NPC", false));

// Create a conversation: [ID 0=START] --> [ID 1=Hello]
int conversationID = 1;
var conversationTitle = "My Conversation";
var conversation = template.CreateConversation(conversationID, conversationTitle);
conversation.ActorID = playerID;
conversation.ConversantID = npcID;
database.conversations.Add(conversation);

// START node: (Every conversation starts with a START node with ID 0)
var startNode = template.CreateDialogueEntry(0, conversation.id, "START");
node.ActorID = playerID;
node.ConversantID = npcID;
startNode.Sequence = "None()"; // START node usually shouldn't play a sequence.
conversation.dialogueEntries.Add(startNode);

// Actual dialogue node ("Hello") with ID 1:
var helloNode = template.CreateDialogueEntry(1, conversation.id, string.Empty);
helloNode.ActorID = npcID; // NPC speaks this line.
helloNode.ConversantID = playerID;
helloNode.DialogueText = "Hello";
conversation.dialogueEntries.Add(helloNode);

// Link from START to Hello:
var link = new Link(conversation.id, startNode.id, conversation.id, node.id);
startNode.outgoingLinks.Add(link);

// And what the heck - might as well add it to the runtime environment and play it:
DialogueManager.AddDatabase(database);
DialogueManager.StartConversation(conversationTitle);
zarnes
Posts: 7
Joined: Fri Dec 29, 2017 9:36 am

Re: Can't create variable and databases

Post by zarnes »

Good morning,

Adding a conversation id worked perfectly. I didn't noticed this property, now it's working without error.
Thank you very much for your help :)

Have a good day and happy new year !
Romain
User avatar
Tony Li
Posts: 20603
Joined: Thu Jul 18, 2013 1:27 pm

Re: Can't create variable and databases

Post by Tony Li »

Hi Romain,

Glad to help! Happy new year!
Post Reply