Access C# variables in the Dialogue System

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ujuj04
Posts: 30
Joined: Sun May 21, 2023 7:34 pm

Access C# variables in the Dialogue System

Post 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.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Access C# variables in the Dialogue System

Post 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.
ujuj04
Posts: 30
Joined: Sun May 21, 2023 7:34 pm

Re: Access C# variables in the Dialogue System

Post by ujuj04 »

Got it, thanks!
ujuj04
Posts: 30
Joined: Sun May 21, 2023 7:34 pm

Re: Access C# variables in the Dialogue System

Post 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!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Access C# variables in the Dialogue System

Post 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;
}
Post Reply