Trying to use the Alert System, Not enough guide

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
sabther
Posts: 7
Joined: Tue Nov 20, 2018 3:38 am

Trying to use the Alert System, Not enough guide

Post by sabther »

Hi

I am trying to use alert system for my project.

I want to have different lines as feedback to the player and only show preferred line according to players action.

for example, I want to do a "checkpoint reached " alert when my player enters into a specific trigger.

I want to use my code on the Player to control this event, can you provide me more guide to it?

Thanks you so much!
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to use the Alert System, Not enough guide

Post by Tony Li »

Hi,

You can do this without code by using a trigger collider and a Dialogue System Trigger component. Here's an example:

Image

The Dialogue System Trigger above checks if a dialogue database variable named "ReachedCheckpoint1" has not been set to true it. If it hasn't been set, the trigger sets it true and shows an alert message.

To do the same in code, use DialogueManager.ShowAlert and DialogueLua.GetVariable/SetVariable:

Code: Select all

void OnTriggerEnter(Collider other) {
    if (!DialogueLua.GetVariable("ReachedCheckpoint1").asBool) {
        DialogueLua.SetVariable("ReachedCheckpoint1", true);
        DialogueManager.ShowAlert("Reached Checkpoint 1");
    }
}
Alerts can use the Dialogue System's localization system. So if you've assigned translations for "Reached Checkpoint 1" to the Dialogue Manager's text table, it will automatically show the translation for the current language.

And alerts can use [var=varName] and [lua(code)] markup tags. Example:

Code: Select all

DialogueManager.ShowAlert("Reached Checkpoint 1. Great job, [var=PlayerNickname]!");
sabther
Posts: 7
Joined: Tue Nov 20, 2018 3:38 am

Re: Trying to use the Alert System, Not enough guide

Post by sabther »

Hello Tony

I still want to command the Alert system purely with the code.

I did some simple test like this:

Code: Select all

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

public class DialogueAlertSystem : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown("space"))
        {
            print("space key was pressed for test Alert System");
            DialogueManager.ShowAlert("Reached Checkpoint 1");
        }

    }
However when every time I press the space sky it shows the debug, but not the alert message. Can you help me to fix it?
It is vital important for me to access the alert system by code.

Ps: the Trigger solution works in my scene, so I think there is something wrong with the code
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to use the Alert System, Not enough guide

Post by Tony Li »

If the trigger works, then DialogueManager.ShowAlert() should work in the same scene because that's what the trigger calls.

Are there any error messages?

Is a dialogue UI assigned to the Dialogue Manager?

Do you have another script in the project that's named DialogueManager and has a ShowAlert() method?

Can you send me a unitypackage containing an example scene and the script?
sabther
Posts: 7
Joined: Tue Nov 20, 2018 3:38 am

Re: Trying to use the Alert System, Not enough guide

Post by sabther »

Hello Tony

There is no error messages.

A dialogue UI already assigned to the Dialogue Manager

I made some changes to the code as:

Code: Select all

	void Start () {
        DialogueManager.ShowAlert("hahah");
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown("space"))
        {
            TestAlert();
        }

    }

    void TestAlert()
    {
        DialogueManager.ShowAlert("new alert");
        print("space key was pressed for test Alert System");
    }

The alert shows on the start of the game, a hahah alert appers

but the input space bar only shows the debug in the console, not the alert.

Can you test it on your end ? I will try to give you a package of the scene. But every time i try to export a package it wants to include everything in the project
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to use the Alert System, Not enough guide

Post by Tony Li »

Here's an example:

AlertScriptExample_2019-02-05.unitypackage

The example is in "Dialogue System Examples / Alert Script Example".

If for some reason it doesn't work, please reply with your Unity version and Dialogue System version. If you're using one the dialogue UI prefabs, let me know which one.

I also included an older example in "Dialogue System Examples / Alert Example". It tests different things, but it might be useful to examine.

p.s. - To export only the files you've selected, untick Include dependencies.
sabther
Posts: 7
Joined: Tue Nov 20, 2018 3:38 am

Re: Trying to use the Alert System, Not enough guide

Post by sabther »

Hi Tony

The package you provided work just fine in my project.

It is so wired, I use unity 2018.2 and letterbox template
Scene.rar
(19.09 KiB) Downloaded 68 times
I un-checked the Include dependencies selections, now it the package wound not export with the script..

I will try to build another scene on my end from the scratch
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trying to use the Alert System, Not enough guide

Post by Tony Li »

Your test scene worked for me:

Image

Could something unrelated to the Dialogue System be causing a conflict?

To export only specific files, select all of the files that you want to export, and untick Include dependencies:

Image

This is the exact script I used:

Code: Select all

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

public class DialogueAlertSystem : MonoBehaviour
{
    void Start()
    {
        DialogueManager.ShowAlert("hahah");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            TestAlert();
        }

    }

    void TestAlert()
    {
        DialogueManager.ShowAlert("new alert");
        print("space key was pressed for test Alert System");
    }
}
Post Reply