Extracting data from a response

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Extracting data from a response

Post 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
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Extracting data from a response

Post 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.
bluebuttongames
Posts: 91
Joined: Tue Jul 14, 2015 8:22 am

Re: Extracting data from a response

Post by bluebuttongames »

You the man, Tony.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Extracting data from a response

Post by Tony Li »

Glad I could help! :-)
Post Reply