Impatient NPC (please help)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
GregOfTomorrow
Posts: 2
Joined: Mon Sep 07, 2015 11:09 pm

Impatient NPC (please help)

Post by GregOfTomorrow »

I'm trying to make an NPC that will start talking again if the Player doesn't choose a dialogue option fast enough.

I've created a script that continuously updates a "patience" variable using...

Code: Select all

DialogueLua.SetVariable ("patience", patience);
...and...

Code: Select all

DialogueLua.GetVariable ("patience").AsFloat;

and I've confirmed by using...

Code: Select all

Debug.Log ("patience = "+DialogueLua.GetVariable ("patience").AsFloat);
...that the variable is in fact going down to zero (though the variable I see in the Database Inspector doesn't seem to move from its original value).


Does anyone know what I'm doing wrong or if my entire approach is flawed? Please help!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Impatient NPC (please help)

Post by Tony Li »

Hi,

That code will work to count down a patience meter. But when it hits zero, what do you do?

[EDIT: It just occurred to me that your dialogue entry might have a Condition that checks the Patience variable. Conditions are only checked before dialogue entries are shown; they're not evaluated continuously while the entry is onscreen.]

The easiest solution might be to use a different approach. You can set a Response Timeout in the Dialogue Manager's Input Settings. If it's non-zero, the dialogue UI will take some action. The default action auto-selects the first response. You could make it something like "[say nothing]".

If you don't want to auto-select the first response, you can change the action to End Conversation, and then add a script that has an OnConversationTimeout method. In this method, you can restart the conversation at a certain point, either by manually calling DialogueManager.StartConversation with a specific entry ID or by setting a variable that the conversation could check as a condition. Or you could make the NPC bark, instead of restarting the conversation, and walk away.

(BTW, if you don't want to show the timer while it's counting down, you can add a CanvasGroup to it and set its Alpha to zero.)

If you don't want to use the built-in timer, you can manually change the conversation to another dialogue entry by using code similar to below:

Code: Select all

// Get the current conversation's ID:
var conversationID = DialogueManager.CurrentConversationState.subtitle.dialogueEntry.conversationID;

// This is the dialogue entry we want to jump to when impatient:
var entryID = 42; // (Replace with your number/algorithm.)

// Get the dialogue entry:
var impatientEntry = DialogueManager.MasterDatabase.GetDialogueEntry(conversationID, entryID);

// Get the conversation state for that entry:
var impatientState = DialogueManager.ConversationModel.GetState(impatientEntry);

// Change the conversation to that state:
DialogueManager.ConversationController.GotoState(impatientState); 
Those are just some ideas off the top of my head. If they don't help, let me know. There's always more than one way to skin a cat. :-)

EDIT: Another idea is to write a custom sequencer command to jump to a specified entry, which is actually really easy using the provided template. The command could fire at a specified time, like this:
  • Dialogue Text: "So what do you say?"
  • Response Menu Sequence: GotoEntry(42)@5
The entry above will show "So what do you say?". During the response menu, it will play the sequence above. If the player selects a response before 5 seconds are up, it will cancel the sequence, so GotoEntry will never fire.
GregOfTomorrow
Posts: 2
Joined: Mon Sep 07, 2015 11:09 pm

Re: Impatient NPC (please help)

Post by GregOfTomorrow »

Thanks Tony. That's a lot to take in. I'll let you know when I have time to go through it in depth and try your suggestions out. It seems like you have a solid grasp of what I'm trying to do. Thanks for your great response.
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Impatient NPC (please help)

Post by Tony Li »

Sorry about the information dump. Feel free to just give it a light skim-over and then ask for more details about whichever approach you'd like to take. Using a Response Timeout is easiest, but it might not be exactly what you're looking for.
Post Reply