Page 1 of 1
Extracting data from a response
Posted: Thu Jun 23, 2016 6:33 pm
by bluebuttongames
Hi there,
Quick one I couldn't find a specific example in the documentation.
So each of my player responses has a "Difficulty" field. From my own code how can I extract this value?
Pseudocode of what I'm after:
string diff = DialogueManager.CurrentReponses.Response1.Get("Difficulty");
Thanks,
BB
Re: Extracting data from a response
Posted: Thu Jun 23, 2016 7:57 pm
by Tony Li
Hi,
You can put a script with a method like this on your Dialogue Manager:
Code: Select all
using PixelCrushers.DialogueSystem;
...
void OnConversationResponseMenu(Response[] responses) {
foreach (var response in responses) {
// This code assumes Difficulty is an int, but you can look it up as other types too:
var diff = Field.LookupInt(response.destinationEntry.fields, "Difficulty");
Debug.Log("Difficulty of response " + response.destinationEntry.DialogueText + " = " + diff);
}
}
API References:
Or go through
DialogueManager.CurrentConversationState yourself:
Code: Select all
foreach (var response in DialogueManager.CurrentConversationState.pcResponses) {
var diff = Field.LookupInt(response.destinationEntry.fields, "Difficulty");
Debug.Log("Difficulty of response " + response.destinationEntry.DialogueText + " = " + diff);
}
API Reference:
Or if you only want to look at the difficulty of the player's selected response after the player has selected it, you can add an OnConversationLine method:
Code: Select all
void OnConversationLine(Subtitle subtitle) {
Debug.Log("Difficulty: " + Field.LookupInt(subtitle.dialogueEntry.fields, "Difficulty"));
}
Or look at DialogueManager.CurrentConversationState.subtitle.dialogueEntry.
Re: Extracting data from a response
Posted: Fri Jun 24, 2016 4:38 pm
by bluebuttongames
You the man, Tony.
Re: Extracting data from a response
Posted: Fri Jun 24, 2016 5:08 pm
by Tony Li
Glad I could help!