Hi Tony.
I want to register the function GetPassengerInfo, it has an argument of int.
But I don't know what to put in the brackets when registering the function.
what to put in Lua Function Registration argument
- DearDeerDee
- Posts: 30
- Joined: Mon Mar 22, 2021 10:00 am
- DearDeerDee
- Posts: 30
- Joined: Mon Mar 22, 2021 10:00 am
Re: what to put in Lua Function Registration argument
Oh I just realized that the parameter must be of double type.
How do I cast from double to int then?
How do I cast from double to int then?
Re: what to put in Lua Function Registration argument
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:
Write a C# method for each basic variable that you want to read in the Dialogue System. Example:
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:
Then you can use it in your conversations like this example:
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;
}
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;
}
Code: Select all
Lua.RegisterFunction("GetPassengerGroupSeatingOrder", null,
SymbolExtensions.GetMethodInfo(() => GetPassengerGroupSeatingOrder((double)0));
Lua.RegisterFunction("GetPassengerGroupCategory", null,
SymbolExtensions.GetMethodInfo(() => GetPassengerGroupCategory((double)0));
- 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
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:
The registration of the method:
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
}
Code: Select all
Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod((bool)default)));
Re: what to put in Lua Function Registration argument
Hi,
You can just use true or false:
or default:
but I think true or false is simpler. Either one is fine.
You can just use true or false:
Code: Select all
Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod(false)));
Code: Select all
Lua.RegisterFunction("ExampleMethod", this, SymbolExtensions.GetMethodInfo(() => ExampleMethod(default(typeof(bool)))));