what to put in Lua Function Registration argument

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
DearDeerDee
Posts: 30
Joined: Mon Mar 22, 2021 10:00 am

what to put in Lua Function Registration argument

Post 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 3715 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 3715 times
User avatar
DearDeerDee
Posts: 30
Joined: Mon Mar 22, 2021 10:00 am

Re: what to put in Lua Function Registration argument

Post 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 3713 times
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: what to put in Lua Function Registration argument

Post 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."
Baldigar
Posts: 1
Joined: Sun Sep 19, 2021 8:14 pm

Re: what to put in Lua Function Registration argument

Post 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)));
User avatar
Tony Li
Posts: 22158
Joined: Thu Jul 18, 2013 1:27 pm

Re: what to put in Lua Function Registration argument

Post 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.
Post Reply