Recording response value

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mikeasci
Posts: 10
Joined: Fri Jan 07, 2022 5:41 pm

Recording response value

Post by mikeasci »

Hi,
When the player selects a response, I would like to be able to save some data about the response. The player has 3 responses to choose from. Depending on which response they chose, they receive a grade of red, yellow or green. I would like to save that value.

On the variable's tab, I created a variable called ResponseColor. In the Inspector, for each response node, I added a Script >> Variable >> ResponseColor and set it to red, yellow or green. My question is, how can I read back the value of ResponseColor when a response is selected?
mikeasci
Posts: 10
Joined: Fri Jan 07, 2022 5:41 pm

Re: Recording response value

Post by mikeasci »

I just found it in the documentation. I didn't think of looking in the LUA code section of the docs.

I used GetVariable["ResponseColor"] to retrieve the value.


My next question: How can I get a reference to the color of the response box? I would like it to flash the color red if they chose a response that has a value "Red".
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Recording response value

Post by Tony Li »

Hi,

I assume you're referring to the C# method DialogueLua.GetVariable("ResponseColor").asString.

And I also assume you're referring to the background image of the response menu panel. If so, then generally speaking you can get it like this:

Code: Select all

StandardUIMenuPanel responseMenuPanel = DialogueManager.standardDialogueUI.conversationUIElements.defaultMenuPanel;
Image backgroundImage = responseMenuPanel.panel as Image;
switch (DialogueLua.GetVariable("ResponseColor").asString)
{
    case "red":
        backgroundImage.color = Color.red;
        break;
    case "yellow":
        backgroundImage.color = Color.yellow;
        break;
    case "green";
        backgroundImage.color = Color.green;
        break;
}
mikeasci
Posts: 10
Joined: Fri Jan 07, 2022 5:41 pm

Re: Recording response value

Post by mikeasci »

Hi,
That worked perfectly. Thank you for the help.

Now I can't figure out how to keep the response buttons showing for a few seconds after the choice is made. It currently flashes 'red' and moves on the next node in the conversation. I would like to leave the response on the screen for 3 seconds before moving onto the next node.

I added Delay(3) command to the Default Response Menu Sequence field on the Dialogue Manager. However, it didn't seem to delay the closing of the response menu at all.
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Recording response value

Post by Tony Li »

Configure the response buttons' Button > OnClick() event to call your own method. If the OnClick() event has anything already assigned to it, the StandardUIResponseButton component won't add its OnClick() method to the Button's OnClick() event.

Assign a method that colors the response menu panel red, waits 3 seconds, and then calls the button's StandardUIResponseButton.OnClick() method.

In that method, you could also prevent the player from clicking any buttons again during the 3-second period. You can do this by setting the buttons' Button > Interactable properties false or by adding a Canvas Group and setting its Interactable property false. Remember to set Interactable true again as you exit the method.
mikeasci
Posts: 10
Joined: Fri Jan 07, 2022 5:41 pm

Re: Recording response value

Post by mikeasci »

I have OnClick calling my own method but I ran into a problem. The value for the variable "ResponseColor" is not set until I run StandardUIResponseButton.OnClick(). How can I set ResponseColor value in the method that I attached to OnClick()?
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Recording response value

Post by Tony Li »

Hi,

You can store the color in a custom field in your response dialogue entry. To do this, inspect the dialogue entry and expand All Fields. Then click "+" to add a field, for example named "ResponseColor".

In your method, you can check the StandardUIResponseButton component's response.destinationEntry property:

Code: Select all

void YourOwnOnClickMethod()
{
    var entry = GetComponent<StandardUIResponseButton>().response.destinationEntry;
    string colorName = Field.LookupValue(entry.fields, "ResponseColor");
}
mikeasci
Posts: 10
Joined: Fri Jan 07, 2022 5:41 pm

Re: Recording response value

Post by mikeasci »

Thanks Tony! That is exactly what I needed.
User avatar
Tony Li
Posts: 22149
Joined: Thu Jul 18, 2013 1:27 pm

Re: Recording response value

Post by Tony Li »

Great! Happy to help.
Post Reply