Page 1 of 1

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

Posted: Sun Sep 06, 2020 8:26 am
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.

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

Posted: Sun Sep 06, 2020 8:57 am
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)