Page 1 of 1
How to reference a fonction to the dialogue system
Posted: Wed Feb 09, 2022 2:00 pm
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.
Re: How to reference a fonction to the dialogue system
Posted: Wed Feb 09, 2022 3:08 pm
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.
Re: How to reference a fonction to the dialogue system
Posted: Wed Feb 09, 2022 3:16 pm
by Tsuki
OMG that was so simple ! and its working thank you very much for you replay !
Re: How to reference a fonction to the dialogue system
Posted: Wed Feb 09, 2022 3:29 pm
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.