Substring replacement

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

korsak42 wrote: Sat Sep 17, 2022 8:10 pmOh, that's not good, but it's still hard to put into words how grateful I am for your help. I'm trying to save money now so I can buy the full version and not have to suffer anymore.
The Dialogue System and several other tools are in a Humble Bundle sale: Unity Tools Bundle

You can get the entire bundle for $30 USD. That's 98% off the regular price. The sale ends in 4 days.
korsak42 wrote: Sat Sep 17, 2022 8:10 pmDid you see any text in the Continue button?
Change the alpha value of the text's Color to 255:

colorAlpha.png
colorAlpha.png (82.44 KiB) Viewed 1043 times
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Hi again!
I bought full version and tried to replace legacy text component with TextMeshPro but after that a bug with the font appeared - Cyrillic letters are shown in the default font and only Latin characters are shown normally. I deleted and created a new asset, but that didn't help.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

Hi,

Thanks for buying the Dialogue System!

Check the font that's assigned to your TextMeshProUGUI component. Make sure the font asset itself has Cyrillic characters.

You can read more about TextMesh Pro fonts here.
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Hi, again!
My project is developing little by little and now it's time to generate dialogs at runtime. At the moment I don't want to generate the whole conversation in a script, I only want to generate the answer options. Hence I have two questions:
1. I can't find anywhere a way to pass a conversation ID and a specific node ID to the script. (already found, sorry).
1.1 How can I put a link to a custom script in the created node?
2. How do I remove the created nodes from the conversation:

P.S. Based on the scrollingUI prefab, I created mine when I was using the trial version (which did not support TextMeshPro), now I need to replace the legacy text component with TextMeshPro. How can I do this?
UPD: I tried to do it according to the materials I found on the forum, however, it did not work (if it creates the necessary nodes, it does not show them). These functions are called at the moment when the player enters the node to which the answers should appear. Could you point out where I went wrong?

Code: Select all

    public void CreateResponseTree(List<Narrator> narrators)
    {
        int i = 0;
        foreach (Narrator narrator in narrators)
        {
            CreateReply(++i);
        }
    }
    private void CreateReply(int i)
    {
        var conversationID = DialogueManager.currentConversationState.subtitle.dialogueEntry.conversationID;
        int nodeID = DialogueManager.currentConversationState.subtitle.dialogueEntry.id;
        var template = Template.FromDefault();
        Conversation conversation = DialogueManager.masterDatabase.GetConversation(conversationID);
        var startNode = DialogueManager.currentConversationState.subtitle.dialogueEntry;
        var responseNode = template.CreateDialogueEntry(template.GetNextDialogueEntryID(conversation), conversation.id, string.Empty);
        responseNode.DialogueText = $"Approach a tavern visitor #{i}";
        var link = new Link(conversation.id, nodeID, conversation.id, responseNode.id);
        startNode.outgoingLinks.Add(link);
    }
Last edited by korsak42 on Wed Nov 02, 2022 10:09 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

Hi,

> I need to replace the legacy text component with TextMeshPro. How can I do this?

To switch to TextMesh Pro, see: TextMesh Pro Support.

> 1.1 How can I put a link to a custom script in the created node?

Register your script's method(s) with Lua (manual, tutorial) and put them in the node's Script field.

> 2. How do I remove the created nodes from the conversation

Are you creating the conversation in the Dialogue Editor / some other editor? If so, it will already have a structure such as:

conversationStructure.png
conversationStructure.png (10.89 KiB) Viewed 994 times

If your runtime answers will use the same structure, then you can change the values of the responses in an OnConversationResponseMenu() method:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
{
    for (int i = 0; i < responses.Length; i++)
    {
        responses[i].formattedText.text = $"Answer {i} text.";
    }
}

If the number of runtime answers will differ from the structure in the conversation, you should make a new conversation. (See here.)
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Tony Li wrote: Wed Nov 02, 2022 10:07 am > 1.1 How can I put a link to a custom script in the created node?
sorry for the inaccuracy, I meant to put a custom script in a node that is created through a C # script.

Can I just paste the same line that I write in the Script field (like this), or do I need to change something additionally?

Code: Select all

responseNode.userScript = "[Variable[\"NarratorType\"] = \"0\"]";
Tony Li wrote: Wed Nov 02, 2022 10:07 am If the number of runtime answers will differ from the structure in the conversation, you should make a new conversation.
So, I cannot add another one to that three responses at runtime, right?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

> sorry for the inaccuracy, I meant to put a custom script in a node that is created through a C # script.
> Can I just paste the same line that I write in the Script field (like this), or do I need to change something additionally?
>

Code: Select all

responseNode.userScript = "[Variable[\"NarratorType\"] = \"0\"]";
Yes, you can do that.

> So, I cannot add another one to that three responses at runtime, right?

Not in OnConversationResponseMenu(). But you can do it with a subclass of StandardDialogueUI or StandardUIMenuPanel. I'll explain using StandardDialogueUI. Make a subclass that overrides ShowResponses(). Example:

Code: Select all

public class MyDialogueUI : StandardDialogueUI
{
    public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
    {
        // Add an extra response:
        var formattedText = FormattedText.Parse("This is a new response.");
        var destinationEntry = DialogueManager.masterDatabase.GetDialogueEntry(7, 42); // Get conv ID 7, entry ID 42.
        var newResponse = new Response(formattedText, destinationEntry);
        var newResponses = new List<Response>(responses);
        newResponses.Add(newResponse);
        base.ShowResponses(subtitle, newResponses.ToArray(), timeout);
    }
}
Or you can create a new database and conversation (as in the link in my previous reply) and manipulate that conversation by clearing and adding responses at runtime.
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Tony Li wrote: Wed Nov 02, 2022 11:39 am But you can do it with a subclass of StandardDialogueUI or StandardUIMenuPanel. I'll explain using StandardDialogueUI.
But if I reload this method, then it will be called every time it needs to show the responses, right? If yes, then this is not exactly what I need. Basically, I can create a "ShowGeneratedResponse" method or something like that. But the question remains how to call it if it is in the StandardUI class. Are there any ways to create additional nodes through CustomScript?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

> Are there any ways to create additional nodes through CustomScript?

Yes. First, tick the Dialogue Manager's Other Settings > Instantiate Database. This will create an in-memory copy of the dialogue database instead of directly using the dialogue database asset file. Now you can change it as much as you want. You can add new dialogue entries (use Template.CreateDialogueEntry() and add it to the conversation's dialogueEntries list) and link them by updating the parent entry's outgoingLinks list.
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Tony Li wrote: Wed Nov 02, 2022 1:34 pm > Are there any ways to create additional nodes through CustomScript?

Yes. First, tick the Dialogue Manager's Other Settings > Instantiate Database. This will create an in-memory copy of the dialogue database instead of directly using the dialogue database asset file. Now you can change it as much as you want. You can add new dialogue entries (use Template.CreateDialogueEntry() and add it to the conversation's dialogueEntries list) and link them by updating the parent entry's outgoingLinks list.
Hm, this tick happened on start of play mode, right?
I've tried to create responses with this code, but it didn't show anything (narrator is a class which contains some ingame info):

Code: Select all

public void CreateResponseTree(List<Narrator> narrators)
    {
        int i = 0;
        foreach (Narrator narrator in narrators)
        {
            CreateReply(++i);
        }
    }
    private void CreateReply(int i)
    {
        var conversationID = DialogueManager.currentConversationState.subtitle.dialogueEntry.conversationID;
        int nodeID = DialogueManager.currentConversationState.subtitle.dialogueEntry.id;
        var template = Template.FromDefault();
        Conversation conversation = DialogueManager.masterDatabase.GetConversation(conversationID);
        var startNode = DialogueManager.currentConversationState.subtitle.dialogueEntry;
        var responseNode = template.CreateDialogueEntry(template.GetNextDialogueEntryID(conversation), conversation.id, string.Empty);
        responseNode.ActorID = 1;
        responseNode.ConversantID = 2;
        responseNode.DialogueText = $"Approach a tavern visitor #{i}";
        conversation.dialogueEntries.Add(responseNode);
        var link = new Link(conversation.id, nodeID, conversation.id, responseNode.id);
        startNode.outgoingLinks.Add(link);
        responseNode.userScript = "[Variable[\"NarratorType\"] = \"0\"]";
    }
I will add more information. Here are two screenshots, on the first one, the red circle indicates the place where the scripts are fired (the scripts are indicated on the second screenshot), the white circle indicates the place to which new responses are attached, the yellow circle indicates the response that should remain (it exits the dialogue). Scripts that are on the second screenshot:
1. Get a list of characters in the tavern.
2. Create a description of these characters (the text is placed in a node in a white circle).
3. Create replies (does not work, it contains a link to the methods that I indicated above, they are not registered in Lua (there was no registration in the example) and are in another C # script).

Image Image
Post Reply