Page 1 of 1
Access C# variables in the Dialogue System
Posted: Sun May 21, 2023 10:21 pm
by ujuj04
Hey, in your YouTube tutorial series there was a guide on how to access C# methods in the Dialogue System. But what if I want it to be possible to change a lot of different Boolean variables from my C# scripts in the Dialogue System. Is there a good way to link them? Thanks in advance.
Re: Access C# variables in the Dialogue System
Posted: Sun May 21, 2023 10:36 pm
by Tony Li
Hi,
Use C# methods to get and set your C# variables. For example:
Code: Select all
private int mana;
public double GetMana() { return mana; }
public void SetMana(double value) { mana = (int)value; }
Then register those C# methods with Lua.
Re: Access C# variables in the Dialogue System
Posted: Sun May 21, 2023 10:39 pm
by ujuj04
Got it, thanks!
Re: Access C# variables in the Dialogue System
Posted: Mon May 22, 2023 12:07 am
by ujuj04
Hey coming back on this topic.
How would I rewrite this if I had a bool?
Lua.RegisterFunction(nameof(DebugLog), this, SymbolExtensions.GetMethodInfo(() => DebugLog(string. Empty)));
Thanks in advance!
Re: Access C# variables in the Dialogue System
Posted: Mon May 22, 2023 8:26 am
by Tony Li
Here are two examples:
Code: Select all
Lua.RegisterFunction(nameof(IsMorning), this, SymbolExtensions.GetMethodInfo(() => IsMorning()));
Lua.RegisterFunction(nameof(SetPlayerHappy), this, SymbolExtensions.GetMethodInfo(() => SetPlayerHappy(false)));
bool IsMorning() // This function returns a bool.
{
return currentHour < 12;
}
void SetPlayerHappy(bool value) // This function accepts a bool parameter.
{
happy = value;
}