Page 1 of 1
Recording response value
Posted: Tue Feb 15, 2022 7:07 pm
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?
Re: Recording response value
Posted: Tue Feb 15, 2022 8:04 pm
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".
Re: Recording response value
Posted: Tue Feb 15, 2022 9:24 pm
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;
}
Re: Recording response value
Posted: Wed Feb 16, 2022 3:53 pm
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.
Re: Recording response value
Posted: Wed Feb 16, 2022 4:23 pm
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.
Re: Recording response value
Posted: Fri Feb 18, 2022 2:51 pm
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()?
Re: Recording response value
Posted: Fri Feb 18, 2022 3:06 pm
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");
}
Re: Recording response value
Posted: Tue Feb 22, 2022 12:18 pm
by mikeasci
Thanks Tony! That is exactly what I needed.
Re: Recording response value
Posted: Tue Feb 22, 2022 1:26 pm
by Tony Li
Great! Happy to help.