new to Dialogue system and need some help :)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Thundy
Posts: 6
Joined: Fri Nov 24, 2017 1:42 pm

new to Dialogue system and need some help :)

Post by Thundy »

Hi all,

I'm new to the dialogue system and am having some issues. I've just realised that i can create all my persistent game variables inside the system rather than in a separate class, which is awesome but i'm having trouble accessing them. i,e i have a player cash variable which i want to be able to display onscreen at all times, as part of the UI, but i cant seem to work out how to do it.

I know this is probably dead easy, like a single line of code in the text field but if anyone could help me out that would be super.

Thanks Muchly
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: new to Dialogue system and need some help :)

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!

In your C# or UnityScript script, use DialogueLua.GetVariable:

Code: Select all

using PixelCrushers.DialogueSystem;
...
myCashText.text = DialogueLua.GetVariable("cash").AsFloat;

If you don't want to do any scripting, you can show your cash variable in the quest tracker HUD:

(In the instructions below, I assume you created a Number variable named "cash".)

1. Create a quest with these settings:
  • State: active
  • Trackable: Ticked
  • Track On Start: Ticked
  • Description: Cash: $[var=cash]
2. Make sure your Dialogue Manager has a quest tracker HUD. If you started with the default Dialogue Manager prefab in the Prefabs folder, it has a quest tracker HUD.

The Dialogue System will replace the tag "[var=cash]" with the value of the cash variable. For example, if Money is cash, then the quest tracker HUD will show "Cash: $42".


If you change cash in a conversation, use the sequencer command UpdateTracker():

- Dialogue Text: "Here's $5."
- Script: Variable["cash"] = Variable["cash"] + 5
- Sequence: {{default}}; UpdateTracker()

(The keyword {{default}} tells the Dialogue System to also use the default sequence defined on the Dialogue Manager.)


If you want to manage it in code, use DialogueLua.GetVariable() and DialogueLua.SetVariable():

Code: Select all

using PixelCrushers.DialogueSystem;
...
var amount = DialogueLua.GetVariable("cash").AsFloat;
var newAmount = amount + 5;
DialogueLua.SetVariable("cash", amount);
DialogueManager.SendUpdateTracker(); // Update "quest" HUD if you're using it.
Thundy
Posts: 6
Joined: Fri Nov 24, 2017 1:42 pm

Re: new to Dialogue system and need some help :)

Post by Thundy »

That's Awesome. Thanks so much Tony
Thundy
Posts: 6
Joined: Fri Nov 24, 2017 1:42 pm

Re: new to Dialogue system and need some help :)

Post by Thundy »

I did have one other question.

My game is pretty much just a series of conversations. I want the background image on the screen to change as the conversation progresses a-la cutscene. The thing is the game is going to be pretty long so that could mean thousands of images.

That being the case i dont know if having a game object for each image, and changing the setactive() for each object would be the most economical way of dealing with this. I know that i can break the game up into scenes but i was wondering if there was still a less memory intensive way of doing this? is there a command i can put into the sequencer which changes the source image of a single image placeholder or is the setactive() method the only viable option?
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: new to Dialogue system and need some help :)

Post by Tony Li »

Hi,

You can write a custom sequencer command to load an image from Resources (or an asset bundle if you prefer to use those). For example, here's a command called Background(image) that loads image and assigns it to the UI element in the scene named "Background Image":

SequencerCommandBackground.cs

Code: Select all

using UnityEngine;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    // Syntax: Background(image)
    public class SequencerCommandBackground : SequencerCommand
    {
        public void Start()
        {
            if (DialogueDebug.LogInfo) Debug.Log("Dialogue System: Sequencer: Background(" + GetParameter(0) + ")");
            var image = DialogueManager.LoadAsset(GetParameter(0), typeof(Sprite)) as Sprite;
            var backgroundImageGO = GameObject.Find("Background Image");
            backgroundImageGO.GetComponent<UnityEngine.UI.Image>().sprite = image;
            Stop();
        }
    }
}
Put your background images in a folder named Resources. Whenever you want to change the background image, add the sequencer command Background(image) to the dialogue entry node, where image is the name of the image.
Thundy
Posts: 6
Joined: Fri Nov 24, 2017 1:42 pm

Re: new to Dialogue system and need some help :)

Post by Thundy »

Tony you are a legend.
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: new to Dialogue system and need some help :)

Post by Tony Li »

Happy to help!
Thundy
Posts: 6
Joined: Fri Nov 24, 2017 1:42 pm

Re: new to Dialogue system and need some help :)

Post by Thundy »

Hi Again Tony. So to keep you on your toes I have another query

ive gotten a bit more of a handle on the dialogue system now and have some ideas about implementation of my game but before i spend weeks plugging it all in i wanted to ask

Im going to have the entire game contained in one scene. there will be different UI's such as the pause menu, dialogue ui and the general "walking around" ui, which i simply toggle on and off as needed. All the game logic will be contained within the dialogue system itself using passthrough conversation nodes which change the background or toggle the ui dependant on the values of lua variables

My question is, based on your experience, do you think the system is robust enough for this or am i going to come up against performance issues?

Also how to i force the dialogue ui to update. If i deactivate the game object and the reactivate it, all the text and portraits vanish which is a bit of a pain
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: new to Dialogue system and need some help :)

Post by Tony Li »

Hi,

Yes, the Dialogue System is robust enough for what you describe. And I'm saying that as an engineer, not a sales person. (Which is a good thing; I'm a lousy sales person. ;) )

If you want to control the dialogue UI's main panel yourself, unassign it from the dialogue UI script's Dialogue > Panel field. You may also need to remove the panel's Animator or assign an animator controller that doesn't hide the panel when it starts.

If that doesn't get you 100% to where you want it to be, please post a sketch or mock-up of what you'd like. I can make some suggestions on how to implement it. You're also always welcome to send an example project any time to tony (at) pixelcrushers.com; I'll be happy to take a look.

And keep in mind that the Dialogue System is completely GUI system-independent. If you don't like the default way that a dialogue UI imlementation works (e.g., Unity UI Dialogue UI), you can customize the scripts (Scripts / Supplemental / UI) or provide your own implementation of the IDialogueUI C# interface. I've cited this example elsewhere on the forum, but one studio's project for vision-impaired users implemented IDialogueUI to do no graphics at all. It used text-to-speech to recite subtitles and response choices, and voice recognition to select responses. So you can really provide whatever implementation you want for IDialogueUI, and the Dialogue System will happily work with it.
Thundy
Posts: 6
Joined: Fri Nov 24, 2017 1:42 pm

Re: new to Dialogue system and need some help :)

Post by Thundy »

Oh wow that sounds cool!

Thanks for the continual help Tony. I'll give it a go and if i cant work it out ill get the crayons out.
Post Reply