Exterior Score element

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
malt
Posts: 10
Joined: Mon Sep 21, 2015 5:03 pm

Exterior Score element

Post by malt »

I want to have a score board on a separate scene than the conversation. How do I reference the those conversation variables from a separate scene?
Also, I was wondering which guide would be best for learning how to create my own UI or GUI mainly for bringing in my own assets?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Exterior Score element

Post by Tony Li »

malt wrote:I want to have a score board on a separate scene than the conversation. How do I reference the those conversation variables from a separate scene?
I suggest using the Dialogue System's Lua environment. Store the score in a variable. In your other scene, call DialogueLua.GetVariable() in a script to get the variable's value. For example:

1. In your dialogue database, on the Variables tab, create a new variable named Score. Set the Type to Number.

2. Update the variable however you want -- for example, using the Dialogue System's PlayMaker Set Variable action, or DialogueLua.SetVariable() in script. Or say you want to add 10 to the score in a conversation. In a dialogue entry's Script field, use:

Code: Select all

Variable["Score"] = Variable["Score"] + 10
3. In your other scene, get the variable value. For example:

Code: Select all

UnityEngine.UI.Text scoreLabel; // Reference to your score UI element.

void Start() {
    scoreLabel.text = DialogueLua.GetVariable("Score").AsInt;
}
malt wrote:Also, I was wondering which guide would be best for learning how to create my own UI or GUI mainly for bringing in my own assets?
The Dialogue System supports many GUI systems. I prefer using Unity UI. It takes a little time to learn, but Unity provides good tutorials.

You could take one of two approaches:

1. Drop the Generic Bundled UI into your scene as a child of the Dialogue Manager GameObject. This will immediately give you a working UI. You can then rearrange the layout and change the textures to your liking. This is how I make custom UIs these days.

2. Alternatively, lay out your UI elements first. Then add a Unity UI Dialogue UI component and hook it up as described in this video tutorial.
malt
Posts: 10
Joined: Mon Sep 21, 2015 5:03 pm

Re: Exterior Score element

Post by malt »

I can see how I would be able to use this:

Code: Select all

 void Start() {
UnityEngine.UI.Text scoreLabel; // Reference to your score UI element.
scoreLabel.text = DialogueLua.GetVariable("Score").AsInt;
}
My question may come from a lack of understanding, but would I need any type of save system like I've seen in tutorials to do this:

1.From my level select scene a UI button is pressed that loads that respective level which is a conversation
2.The conversation is triggered OnStart of that scene
3.The win of a conversation is a condition that is dependent on a score variable which each response has.(If that doesn't make sense here is a link to my hidden values system thread: viewtopic.php?f=3&t=295)
4.The conversation ends with the player either winning or losing where the last player dialogue selection updates a wins variable on specific player response
5.A game object is set as active that gives the player information if they win or lose this object has a child ui button that goes back to the level select scene onClick.
6.If he/she wins the conversation a text field is updated and this would continue for every single level.
7. The level button that was pressed is now grayed out and cannot be selected again.

I may be able to use a loop in the start or update method IF what I think happens doesn't actually happen, but I'm sure you have a better idea than I do. I assume an old scene is destroyed after a new scene is loaded to conserve memory. So, if it does happen do you have any idea what I could do to update a variable so that each time a win is reached in conversation is met in a conversation.
It seems that a single database will share variables, so would a different conversation change those values? Because I'm looking to have my score reset at the start of each conversation and my wins to carry over in order to update that variable correctly.

Also, I can't thank you enough for your help. If there is anything I can do!!! I brag on your product in my game dev class, and will leave a great review in the assets store, but you guys have been saviors!!!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Exterior Score element

Post by Tony Li »

Hi,

Thanks for the kind words about the Dialogue System!

If you put the Dialogue Manager GameObject in your level select scene, it will carry through to other scenes. This includes its variable values. Other GameObjects in the level select scene will be destroyed by default when changing scenes.
  • In your dialogue database, define a variable named "Wins". Set its Type to Number and its Value to 0.
  • In your level select scene, add a script like in my previous post, except use the variable "Wins":

    Code: Select all

    DialogueLua.GetVariable("Wins").AsInt;
  • In the START node of your conversations, reset Score to zero by setting the Script field to:

    Code: Select all

    Variable["Score"] = 0;
You can also use the Dialogue System to record which levels have already been selected:
  • Define variables that match your level names, such as "Level1", "Level2", etc. Set their Type to Boolean and Value to False.
  • In the START node of your conversations, use the Script field to set the variable true. For example, in the Level2 conversation:

    Code: Select all

    Variable["Level2"] = true;
  • In the level select scene, check the variable values. For example, add this script to each level button:

    Code: Select all

    using UnityEngine;
    using PixelCrushers.DialogueSystem;
    
    public class LevelButton : MonoBehaviour {
        public string levelName; //<-- Set to "Level1", etc.
        
        public void Start() { // Disables the button if we've already visited the level.
            var button = GetComponent<UnityEngine.UI.Button>();
            if (button != null) button.interactable = !DialogueLua.GetVariable(levelName).AsBool;
        }
        
        public void OnClick() { //<-- Assign this to the button's OnClick event.
            Application.LoadLevel(levelName);
        }
    }
If you want this information to persist between play sessions (e.g., save a game and load it the next time you play), please see the Save System section.
Post Reply