Page 1 of 1

what to put in Lua Function Registration argument

Posted: Mon Mar 29, 2021 3:30 am
by DearDeerDee
Hi Tony.

I want to register the function GetPassengerInfo, it has an argument of int.
Snipaste_2021-03-29_12-14-52.png
Snipaste_2021-03-29_12-14-52.png (22.44 KiB) Viewed 3720 times

But I don't know what to put in the brackets when registering the function.
Snipaste_2021-03-29_12-15-41.png
Snipaste_2021-03-29_12-15-41.png (12.15 KiB) Viewed 3720 times

Re: what to put in Lua Function Registration argument

Posted: Mon Mar 29, 2021 3:48 am
by DearDeerDee
Oh I just realized that the parameter must be of double type.
How do I cast from double to int then?
Snipaste_2021-03-29_15-46-33.png
Snipaste_2021-03-29_15-46-33.png (32.05 KiB) Viewed 3718 times

Re: what to put in Lua Function Registration argument

Posted: Mon Mar 29, 2021 9:15 am
by Tony Li
Hi,

Use "(int)" in front of a type to cast it as an int.

Only register basic types with Lua. For example, say PassengerGroupData has two variables:

Code: Select all

public class PassengerGroupData
{
    public int seatingOrder;
    public string category;
}
Write a C# method for each basic variable that you want to read in the Dialogue System. Example:

Code: Select all

public static double GetPassengerGroupSeatingOrder(double startID)
{
    return GetPassengerInfo((int)startID).seatingOrder; // (Note: Should really check if GetPassengerInfo returns null.)
}

public static string GetPassengerGroupCategory(double startID)
{
    return GetPassengerInfo((int)startID).category;
}
Since these are static methods, you can use 'null' instead of 'this'. Pass "(double)0" for the parameter to specify that it expects a 'double' value:

Code: Select all

Lua.RegisterFunction("GetPassengerGroupSeatingOrder", null, 
    SymbolExtensions.GetMethodInfo(() => GetPassengerGroupSeatingOrder((double)0));
Lua.RegisterFunction("GetPassengerGroupCategory", null, 
    SymbolExtensions.GetMethodInfo(() => GetPassengerGroupCategory((double)0));
Then you can use it in your conversations like this example:
  • Conditions: GetPassengerGroupSeatingOrder(Variable["PlayerStartID"]) > 3
  • Dialogue Text: Sorry, we're only seating groups 1-3 right now. Please wait at the back of the line."

Re: what to put in Lua Function Registration argument

Posted: Sun Sep 19, 2021 8:23 pm
by Baldigar
I'm asking about this in this thread because it's related to the main topic of it (and because the answer may be valuable to be in the same space as the related information).

Am I correct in thinking that the way you would register a function that accepts a bool argument be as follows?

The method:

Code: Select all

private void ExampleMethod(bool boolValue)
{
	//Statements
}
The registration of the method:

Code: Select all

Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod((bool)default)));

Re: what to put in Lua Function Registration argument

Posted: Sun Sep 19, 2021 8:35 pm
by Tony Li
Hi,

You can just use true or false:

Code: Select all

Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod(false)));
or default:

Code: Select all

Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod(default(typeof(bool)))));
but I think true or false is simpler. Either one is fine.