Passing Display Name of conversant as a string parameter to a registered function

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Sternutation
Posts: 22
Joined: Wed Aug 19, 2020 2:44 pm

Passing Display Name of conversant as a string parameter to a registered function

Post by Sternutation »

Hello,

I have a created a C# method and tried to register it in Lua. This method accepts a string parameter. A snippet of that is available below-

Code: Select all

public void OnEnable()
    {
        // Make the functions available to Lua: (Replace these lines with your own.)
        Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod((string)null)));
    }
    public void OnDisable()
    {
        if (unregisterOnDisable)
        {
            // Remove the functions from Lua: (Replace these lines with your own.)
            Lua.UnregisterFunction("ExampleMethod");
        }
    }
I then registered it in the Lua custom function table, and tried to use it in a dialogue tree. I tried to pass the display name of the current conversant as a string, but I have been getting a syntax error when using Actor[Variable["Conversant"]] or Variable["Conversant"] as the string parameter.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Passing Display Name of conversant as a string parameter to a registered function

Post by Tony Li »

Hi,

Variable["Conversant"] should work. For example, set the Script field to:

Code: Select all

ExampleMethod(Variable["Conversant"])
Note that an actor's table index (aka a dictionary key in C#) may be different from its name. (more info) If the actor's name is "Mister Ed", then its table index will be "Mister_Ed". If you reference the Actor[] table in your Script, use Variable["ConversantIndex"]:

Code: Select all

ExampleMethod(Variable["ConversantIndex"].Name)
Post Reply