How to reference a fonction to the dialogue system

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Tsuki
Posts: 2
Joined: Wed Feb 09, 2022 1:52 pm

How to reference a fonction to the dialogue system

Post by Tsuki »

Hi ! am a noob with this amazing dialogue system and i follow the video Connecting Your C# Methods to Lua, but i still dont understand how can i have access to my fonction on a specific node in the dialogue. Like i want to my npc start my fonction Test(),when i click on change season in the dialogue system. My npc scrip is on a gameobject npc

Sorry for the noob question but i cant find how to do it and thank you very mush in advence.
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to reference a fonction to the dialogue system

Post by Tony Li »

Hi,

Thanks for using the Dialogue System!

I'll assume your HoraeNpc script is on your NPC GameObject. Add these methods to the script:

Code: Select all

void OnEnable()
{
    // Make Test() available to Lua:
    Lua.RegisterFunction(nameof(Test), this, SymbolExtensions.GetMethodInfo(() => Test()));
}

void OnDisable()
{
    Lua.UnregisterFunction(nameof(Test));
}
Then you can use Test() in your dialogue entry node's Script field.
Tsuki
Posts: 2
Joined: Wed Feb 09, 2022 1:52 pm

Re: How to reference a fonction to the dialogue system

Post by Tsuki »

OMG that was so simple ! and its working thank you very much for you replay !
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to reference a fonction to the dialogue system

Post by Tony Li »

Happy to help!

Keep in mind that Lua functions are registered globally. If you register a function named Test() on an NPC named Horae, you shouldn't register a function Test() on another GameObject at the same time.
Post Reply