Page 1 of 1
Using C# For Custom Condition/Script
Posted: Fri May 29, 2020 10:47 pm
by RandomProduct
Hello,
I'm trying to use C# as my primary programming source, as I'm more comfortable with it than Lua. But I'm not sure how to go about this, and there's not a lot of information that I can find on the wiki or this forum. I did find
this function that adds custom functions to the Lua layer. But as far as I can tell, they're added at runtime, meaning I can't use the Lua wizard to add conditions/scripts to dialogue nodes unless I type them by hand.
I also found that there's the "Custom" condition/script choice, but I've had trouble finding any information on how to use that, and the dropdown is blank by default. Maybe that's related, maybe it's not.
Am I missing something? Or doing this wrong?
Thanks
Re: Using C# For Custom Condition/Script
Posted: Sat May 30, 2020 8:14 am
by Tony Li
Hi,
That link points to the (extremely old) legacy version 1.x documentation. Please use the version 2.x documentation available here:
Dialogue System Manual
You can write your code in C# and then use Lua.RegisterFunction() at runtime. It's easiest to start with the template script located in Plugins / Pixel Crushers / Dialogue System / Templates / Scripts.
Then create a Custom Lua Function Info asset in your project. (Create > Pixel Crushers > Dialogue System > Custom Lua Function Info.) In this asset, you can define your functions' signatures -- that is, what parameters it accepts, and what value it returns. These will appear in the "..." Lua dropdown wizards.
Helpful links:
Re: Using C# For Custom Condition/Script
Posted: Mon Jun 08, 2020 4:52 pm
by RandomProduct
Thank you! I'll check these out.
Re: Using C# For Custom Condition/Script
Posted: Mon Jun 08, 2020 5:39 pm
by RandomProduct
Hello -
I seem to be having a problem getting the example script to work. I've followed the steps in the links provided and got so far as being able to add "DebugLog(string)" to the Scripts portion of a dialogue node via the Scripts Wizard. Presumably this means the Lua Register function worked properly. I added a basic string, "Ope", to make sure I got everything right. However, when I click on that dialogue node in-game, nothing is registered to the console.
Any ideas on what I'm missing?
Thanks
Re: Using C# For Custom Condition/Script
Posted: Mon Jun 08, 2020 6:51 pm
by Tony Li
Hi,
Did you add your C# script to the scene (e.g., to the the Dialogue Manager)? Or otherwise set it up so that the Lua.RegisterFunction() method will be executed?
Re: Using C# For Custom Condition/Script
Posted: Thu Jun 11, 2020 9:08 pm
by RandomProduct
I did. I added the example script as a component attached to the Dialogue Manager gameobject. The Lua.RegisterFunction() I use is called in Start().
Re: Using C# For Custom Condition/Script
Posted: Thu Jun 11, 2020 9:42 pm
by Tony Li
Sorry, I'm still not clear on something. Is your C# method being run? You can either add a Debug.Log() line inside your C# method or set a breakpoint and see if the debugger stops there.
Can you paste your C# method and the Lua.RegisterFunction() line into a reply?
If your C# method is not being run, temporarily set the Dialogue Manager's Debug Level to Info. When you play the scene, look for a Console message like this:
Dialogue System: Registering Lua function (your C# method here)
That will let you know that it's properly registered. Also make sure the name matches exactly with what's in your dialogue entry node's Script field, including capitalization.