Detect response via trigger

Announcements, support questions, and discussion for the Dialogue System.
ricjonsu098
Posts: 45
Joined: Sat Jul 30, 2016 8:37 am

Detect response via trigger

Post by ricjonsu098 »

Hello, I have an idea what to do.

Image

As you can see in the image, there are choices A to D.

There will be a dialogue (quiz type) where the NPC at the back will ask a question, then there will be a choices. And when the player climbs on the platform let's say platform A, the answer A will be sent to the NPC.

Is my idea right? This is my idea

Create a script on each platform, on trigger enter, a Sequencer.Message("A") will be sent. and in the sequence in the conversation, I will put @Message(A). Same for platform B and response B, and so on so forth.

Is there any other way to do this? Like there are 4 response, A, B, C, D.

When player climbs on each platform, like I said let's say platform C, response C will be chosen
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Detect response via trigger

Post by Tony Li »

That's pretty close to what I'd suggest. Here's an example scene of what I suggest:

PlatformResponseExample_2016-08-28.unitypackage

And here's how I set it up:

1. In my dialogue database, I defined a Text variable named "Response".

2. I set up the conversation like this:

Image
  • The question node ("What is 1+1?") uses a Sequence that waits for a sequencer message "ChoseResponse".
  • The next node is an empty node with the Sequence set to "None()". This delays evaluation of the response as described here.
  • The answer nodes check the value of the Response variable. The screenshot above only shows the Conditions for B, but A/C/D are similar.
3. I set up the Sequence Triggers on each platform like this:

Image
  • When the player steps on a platform, the Sequence sets the Response variable. Then it calls the Dialogue Manager's OnSequencerMessage("ChoseResponse") method.
ricjonsu098
Posts: 45
Joined: Sat Jul 30, 2016 8:37 am

Re: Detect response via trigger

Post by ricjonsu098 »

I see. This works thanks :) as I've been using Dialogue System, I start to realize that if used correctly, you can create a wide variety of dialogue without coding. Great asset.
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Detect response via trigger

Post by Tony Li »

Thanks! :-)
ricjonsu098
Posts: 45
Joined: Sat Jul 30, 2016 8:37 am

Re: Detect response via trigger

Post by ricjonsu098 »

Oh additional, is there a way to disable clicking the response? Like the responses are shown but cannot be clicked? So that the only way to choose answer is by climbing the platform
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Detect response via trigger

Post by Tony Li »

The easiest way is to position the response menu panel so it's off the screen.
ricjonsu098
Posts: 45
Joined: Sat Jul 30, 2016 8:37 am

Re: Detect response via trigger

Post by ricjonsu098 »

Tony Li wrote:That's pretty close to what I'd suggest. Here's an example scene of what I suggest:

PlatformResponseExample_2016-08-28.unitypackage

And here's how I set it up:

1. In my dialogue database, I defined a Text variable named "Response".

2. I set up the conversation like this:

Image
  • The question node ("What is 1+1?") uses a Sequence that waits for a sequencer message "ChoseResponse".
  • The next node is an empty node with the Sequence set to "None()". This delays evaluation of the response as described here.
  • The answer nodes check the value of the Response variable. The screenshot above only shows the Conditions for B, but A/C/D are similar.
3. I set up the Sequence Triggers on each platform like this:

Image
  • When the player steps on a platform, the Sequence sets the Response variable. Then it calls the Dialogue Manager's OnSequencerMessage("ChoseResponse") method.
Hi, so I've used your solution. It worked. But another problem is shown when I implemented a Time constraint (For example, the player have 15 secs to choose a platform). The problem is, I've set the chars/second to 10 so all of the conversation will display longer before proceeding to the next, but in the quiz, when the player chooses a platform, the chars/second kicks in, it waits for the corresponding second before it proceed to the next dialogue which evaluates the answer.

How I realized this problem is because when the player chooses and steps on the platform, the timer will reset back into 15, then immediately, it must proceed to the next dialogue. But like I've said, the timer resets, but the dialogue waits for the corresponding seconds (chars/second) before proceeding to the evaluation

here's a screenshot

Here is before choosing a platform
Image

Here is where player chooses a platform
Image

You can see that the timer resets, but the evaluation dialogue does not came up. Here is where chars/second kicks in. It waits for the corresponding seconds before proceeding.

Here is the eval dialogue. This comes up after a few seconds where supposedly, it must immediately come up after stepping on the platform
Image
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Detect response via trigger

Post by Tony Li »

How did you implement your timer?

Can you skip the timer when displaying dialogue entries whose Sequence field is "None()"?
ricjonsu098
Posts: 45
Joined: Sat Jul 30, 2016 8:37 am

Re: Detect response via trigger

Post by ricjonsu098 »

Hi here's how I implement the timer

So like the usual, I created 2 Objects, 1 is unity UI which is the UI which contains the timer itself, and the other one is an empty object which contains how I manipulate the timer.

I start/stop the timer using sequence commands.

This sequence is located at the node which contains the question

Code: Select all

SetActive(myTimer, true); //enables the UI
SetEnabled(GameTimer, true, GameTimer); //enables the object which holds the script
This sequence is located at the node which contains the answer

Code: Select all

SetActive(myTimer, false); //same but stops the timer
SetEnabled(GameTimer, false, GameTimer);
This is the script of the timer itself

Code: Select all

using UnityEngine;
using UnityEngine.UI;
using PixelCrushers.DialogueSystem;
using System.Collections;

public class GameTimer : MonoBehaviour {

    public static GameTimer Instance;
    public Text timerText;
    public float timeLeft = 15;
    bool isEnabled = true;
    GameObject objTimer;
    

	// Use this for initialization
	void Start () {
        Instance = this;
        objTimer = GameObject.Find("myTimer");
        objTimer.SetActive(false);
        GameTimer gTimer = GameObject.Find("GameTimer").GetComponent<GameTimer>();
        gTimer.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
        timeLeft -= Time.deltaTime;

        timerText.text = timeLeft.ToString("f2");
        if (timeLeft <= 0)
        {
            timeLeft = 0;
            timerText.text = timeLeft.ToString("f2");
            Debug.Log("Timer stopped");
            timeLeft = 15;
            string message = "Time";
            DialogueLua.SetVariable("Response", message);
            Debug.Log(DialogueLua.GetVariable("Response").AsString);
            DialogueManager.Instance.SendMessage("OnSequencerMessage", "ChooseResponse");
        }

    }

    public void resetTimer()
    {
        timeLeft = 15;
    }

}
I reset the time using a script that is attached on the platforms

Code: Select all

using UnityEngine;
using System.Collections;

public class ResetTimer : MonoBehaviour {

    void OnTriggerEnter (Collider other)
    {
        if (gameObject.name == "ChoiceATrig")
        {
            GameTimer.Instance.resetTimer(); //this simply references another script which has the method resetTimer() which contains a timeLeft = 15, 15 is the initial time, it just sets it back to 15 on trigger enter
        }else if (gameObject.name == "ChoiceBTrig")
        {
            GameTimer.Instance.resetTimer();
        }
        else if (gameObject.name == "ChoiceCTrig")
        {
            GameTimer.Instance.resetTimer();
        }
        else if (gameObject.name == "ChoiceDTrig")
        {
            GameTimer.Instance.resetTimer();
        }
        else if (gameObject.name == "ChoiceTRUETrig")
        {
            GameTimer.Instance.resetTimer();
        }
        else if (gameObject.name == "ChoiceFALSETrig")
        {
            GameTimer.Instance.resetTimer();
        }
    }
}

Image

So in your question, maybe? If the dialogue system reads the sequence after the None(), I can stop the timer using the sequence above.
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: Detect response via trigger

Post by Tony Li »

That should work. In fact, instead of None(), just put your command to deactivate the timer.
Post Reply