Page 1 of 1
Set conditions from my own C#
Posted: Mon Nov 11, 2024 1:27 pm
by GSaloun
Hello,
I'm using Dialogue System connecting with my scripts in C# and with your help i now can edit variables of my scripts directly from a conversation in Dialogue System. My problem now is that i can't setup a condition in Dialogue System using the same variables from my Scripts.
What is the line of code that i need to use in the condition (inside the conversation) to activate the dialogue for example if the "GetKey" is true or if "MaxHealth" is equal to 10?
Below is the code in my script that i'm referring above:
void OnEnable()
{
Lua.RegisterFunction(nameof(MaxHealth), this, SymbolExtensions.GetMethodInfo(() => MaxHealth(0)));
Lua.RegisterFunction(nameof(GetKey), this, SymbolExtensions.GetMethodInfo(() => GetKey(true)));
}
Thanks!
Re: Set conditions from my own C#
Posted: Mon Nov 11, 2024 3:39 pm
by Tony Li
Hi,
That looks good (assuming the C# functions do what you expect). Although maybe GetKey() doesn't need to receive a bool value? Now you just need to set the dialogue entry's Conditions to:
Code: Select all
GetKey(true) == true or MaxHealth() == 10
Re: Set conditions from my own C#
Posted: Mon Nov 11, 2024 5:17 pm
by GSaloun
Hi,
Thanks for your help!
Sorry, i try this, but nothing happens. I think the problem is my function, basically i'm using it to change a bool value and work well setting up by Dialogue System, but using for condition isn't working.
Below is my function:
public void SetMaxHealth(double value) { maxHealth += (int)value; }
public void GetKey (bool value) { getKey = (bool)value; }
void OnEnable()
{
Lua.RegisterFunction(nameof(MaxHealth), this, SymbolExtensions.GetMethodInfo(() => MaxHealth(0)));
Lua.RegisterFunction(nameof(GetKey), this, SymbolExtensions.GetMethodInfo(() => GetKey(true)));
}
The result using the Script inside a conversation in Dialogue System, works well as following:
"GetKey(true)" results in makes the getKey bool change to "true".
"MaxHealth(1)" results in adding 1 into MaxHealth value.
My goal now is use this same variables "getKey" and "maxHealth" as condition to keep the conversation, but i don't know how.
Can you help me? Thanks again!
Re: Set conditions from my own C#
Posted: Mon Nov 11, 2024 7:32 pm
by Tony Li
Hi,
For MaxHealth, I recommend using this technique:
How To: Connect C# Variables to Dialogue System's Lua
If there's only one key, you can do the same thing for SetKey and GetKey. Otherwise you can pass a number, for example, to specify which key.
Example:
Code: Select all
public int health = 100;
public HashSet<int> keys = new HashSet<int>();
private void OnEnable()
{
Lua.RegisterFunction(nameof(SetHealth), this, SymbolExtensions.GetMethodInfo(() => SetHealth(0)));
Lua.RegisterFunction(nameof(GetHealth), this, SymbolExtensions.GetMethodInfo(() => GetHealth()));
Lua.RegisterFunction(nameof(AcquireKey), this, SymbolExtensions.GetMethodInfo(() => AcquireKey(0)));
Lua.RegisterFunction(nameof(HasKey), this, SymbolExtensions.GetMethodInfo(() => HasKey(0)));
}
private void SetHealth(double value) { health = (int)value; }
private double GetHealth() { return health; }
private void AcquireKey(double value) { keys.Add((int)value); }
private bool HasKey(double value) { return keys.Contains((int)value); }
In your Script fields, you can set health and keys like this:
And in Conditions you can check it like this: