Populate "Dialogue Text" from a script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
boz
Posts: 76
Joined: Mon Oct 19, 2020 8:59 pm

Populate "Dialogue Text" from a script

Post by boz »

Howdy :D

So, when promoted for a response, I want to set the options via a list in a script.

The idea is that every time you are prompted for this response, the options will be whatever happens to be in that list at the time.

Say the list is

Code: Select all

public List<string> AvailableResponses = new List<string>();
I'm guessing it would be some sort of variable placed in the Dialogue Text field itself like:

Code: Select all

[lua(AvailableResponses [0])]
I'm not sure if that's how lua works.

HOWEVER, I would also like to create the responses to match the size of the list. Say there are 4 items in the list - maybe upon being prompted to input your response, it would generate via script 4 possible responses based on the items of that list. Or maybe it just has some blank entries ready and if you don't fill them all up it omits them?

My question is - how do I get these scripts talking to the dialogue? Or maybe my question is - is there a better way to go about this? Or a healthy compromise?

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

Re: Populate "Dialogue Text" from a script

Post by Tony Li »

Hi,

It will require a little scripting, but not much. Your example has a list of strings. But how do you know where each string should lead in the conversation tree? Or do they all lead to the same place?

Here are a few different ideas:

1. Write a Lua function (tutorial) that returns the length of the AvailableResponses list (e.g., GetNumResponses). In your conversation tree, add the maximum number of response nodes that your list would have. In each node, set the Conditions so the response node will only be shown if there are enough responses -- e.g., "GetNumResponses() >= 1" for the first node, "GetNumResponses() >= 2" for the second node, etc. Add a script to the Dialogue Manager that has an OnConversationResponseMenu(Response[]) method. In the method, set each Response's formattedText.text to the value of the corresponding string in AvailableResponses. You can also set the Response's destinationEntry to the dialogue entry node that it leads to.


2. Or make a subclass of StandardUIMenuPanel. Override the ShowResponses() method to show your own AvailableResponses instead of its normal behavior. Note that response buttons need a reference to a Response, so you'll need to create a Response for each button.


3. Or you could generate the entire conversation in code. This requires a lot more scripting, though. See: How To: Create a Dialogue Database At Runtime.

Although #1 above looks longer, it's probably the simplest to implement.
Post Reply