Tying a Slider to a Dialogue System Variable

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
AlexNerd
Posts: 39
Joined: Sat Jun 29, 2019 11:46 am

Tying a Slider to a Dialogue System Variable

Post by AlexNerd »

I'm trying to use the Dialogue system to make some turn-based combat, and I currently have the player health as a variable in the dialogue system. How do I make a health slider that adjusts with the health whenever the player takes damages?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tying a Slider to a Dialogue System Variable

Post by Tony Li »

Hi Alex,

Write a C# method, and register it as a Lua function. Something like:

Code: Select all

using PixelCrushers.DialogueSystem;
public UnityEngine.UI.Slider healthBar;
...
void Awake()
{
    Lua.RegisterFunction("SetHealth", this, SymbolExtensions.GetMethodInfo(() => SetHealth((double)0)));
}
public void SetHealth(double health)
{
    DialogueLua.SetVariable("PlayerHealth", health);
    healthBar.value = health;
}
Then use SetHealth() to change the health variable. Instead of setting the Script field to this:

Code: Select all

Variable["Health"] = Variable["Health"] + 10;
use this:

Code: Select all

SetHealth(Variable["Health"] + 10)
AlexNerd
Posts: 39
Joined: Sat Jun 29, 2019 11:46 am

Re: Tying a Slider to a Dialogue System Variable

Post by AlexNerd »

What should I attach the script to? The Dialogue Manager?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Tying a Slider to a Dialogue System Variable

Post by Tony Li »

Hi,

Yes, that's a good choice.
Post Reply