I am trying to take advantage of the Lua Dropdown Wizard and hopefully setup conversation conditions without writing a lot of unique Lua code.
I noticed that Custom Lua Function Info has the option of Variable as a Parameter.
How should I construct a Lua Registered Function to accept a Variable as a parameter?
Thanks!
How to pass Variable parameter in Custom Lua Function
-
- Posts: 13
- Joined: Sun Jan 24, 2021 6:18 pm
Re: How to pass Variable parameter in Custom Lua Function
Hi,
If you choose Variable for the parameter type, then it will pass a value from the Variable[] table. The dropdown will show the variables defined in the Variables panel of the Dialogue Editor. Since these variables can be any type, make sure to match the type of the variable with the type used in your C# method.
For example, if your C# ContainsEntry method is:
then you should select a Text variable in the dropdown.
If your C# ContainsEntry method is:
then you should select a Number variable in the dropdown like this:
If you choose Variable for the parameter type, then it will pass a value from the Variable[] table. The dropdown will show the variables defined in the Variables panel of the Dialogue Editor. Since these variables can be any type, make sure to match the type of the variable with the type used in your C# method.
For example, if your C# ContainsEntry method is:
Code: Select all
public bool ContainsEntry(string entryTitle) {...}
If your C# ContainsEntry method is:
Code: Select all
public bool ContainsEntry(double entryID) {...}
-
- Posts: 13
- Joined: Sun Jan 24, 2021 6:18 pm
Re: How to pass Variable parameter in Custom Lua Function
Hi,
Thank you for responding.
I got it working with Number and Text fields.
Can other field types work?
I tried making a CustomFieldType with a storeFieldAsType = Text but it seems to return null when passed to the condition function.
Thank you for responding.
I got it working with Number and Text fields.
Can other field types work?
I tried making a CustomFieldType with a storeFieldAsType = Text but it seems to return null when passed to the condition function.
Re: How to pass Variable parameter in Custom Lua Function
Hi,
Custom fields are always added as Text (strings).
For example, say you've defined a custom field type named Relationship with three enum values: { Friend, Neutral, Enemy }
And you've defined a variable in the Dialogue Editor's Variables section named RelationshipToPlayer initially set to Neutral.
Internally, the Lua variable will be set to:
If you pass this variable to your custom Lua function, it should be registered to a C# method that accepts a string:
Custom fields are always added as Text (strings).
For example, say you've defined a custom field type named Relationship with three enum values: { Friend, Neutral, Enemy }
And you've defined a variable in the Dialogue Editor's Variables section named RelationshipToPlayer initially set to Neutral.
Internally, the Lua variable will be set to:
Code: Select all
Variable["RelationshipToPlayer"] = "Neutral"
Code: Select all
public bool IsFriendly(string relationship)
{
return relationship == "Friend";
}
-
- Posts: 13
- Joined: Sun Jan 24, 2021 6:18 pm
Re: How to pass Variable parameter in Custom Lua Function
Great I got it working.
Thanks!
Thanks!