Custom Lua Functions for Stats and Modifiers

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
brooklyngamer
Posts: 3
Joined: Fri Jun 16, 2023 12:32 am

Custom Lua Functions for Stats and Modifiers

Post by brooklyngamer »

Hi Tony,

Thanks again for the amazing asset--really helping me get off the ground with Unity so much faster.

Quick question, I've seen partial answers in some previously asked topics but have run into a snag on my end:

I'm trying to implement skill checks within conversations based on player stats. I have two C# scripts--one for Character stats and one for potential stat modifiers down the road--and another broader Character C# script I'm using to edit these stats directly in the Inspector.
Inspector Stats.png
Inspector Stats.png (68.12 KiB) Viewed 247 times
ScriptShot2.png
ScriptShot2.png (193.89 KiB) Viewed 247 times
Ultimately I'm having trouble getting the stat value changes I make in the Inspector to work with a custom Lua Function inside a conversation, and I'm wondering if it may be an error in my stats scripts, or if I'm not registering the C# function correctly or not creating a custom Lua Function correctly in DS--or if it's even possible to tell from your perspective. No noticeable typos I've been able to find across VSCode or Unity either.

This previous topic was helpful: https://www.pixelcrushers.com/phpbb/vie ... hp?p=38729
But haven't had success replicating it fully.

Thanks for your time!

PS, if there's an easier way to store and reference character/player stats directly with DS, would happily use that!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Lua Functions for Stats and Modifiers

Post by Tony Li »

Hi,

At what point is it not working? When you make a stat change in the Inspector and then try to read the stat value using GetSociability() in the Dialogue System?

Are there any errors or warnings in the Console window?
brooklyngamer
Posts: 3
Joined: Fri Jun 16, 2023 12:32 am

Re: Custom Lua Functions for Stats and Modifiers

Post by brooklyngamer »

Thanks for the quick reply,

I do get this convert error: "Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)" So that may be the root of my problem.

However I've been able to bypass that by immediately referring to a public double and not using 'int'--that's when any changes I make in Inspector don't translate to the custom Condition I'm setting on a piece of NPC dialogue. But that could be causing additional problems if I need to first reference the 'int' in my 'CharacterStats' script that I'm pulling into my 'Character' script. Not a huge expert on C#.

Also not entirely sure if I'm setting up the Lua Function correctly from the wizard, what my Element is or if I need a Return Value for something as simple as an 'int' stat.
FunctionSetup.png
FunctionSetup.png (61.63 KiB) Viewed 233 times
Thanks again.
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Lua Functions for Stats and Modifiers

Post by Tony Li »

Hi,

Assuming your SetSociability() function looks like this:

Code: Select all

public void SetSociability(double value)
{
    sociability = value;
}
change it to this:

Code: Select all

public void SetSociability(double value)
{
    sociability = (int)value;
}

For the Custom Lua Function Info:
  • GetSociability:
    Parameters: none (size zero)
    Return Value: Double
    ---
  • SetSociability:
    Parameters: Double (size 1)
    Return Value: None
brooklyngamer
Posts: 3
Joined: Fri Jun 16, 2023 12:32 am

Re: Custom Lua Functions for Stats and Modifiers

Post by brooklyngamer »

Hey Tony,

Thank you, this helped a lot. Was able to create an individual Stat script for each condition-- however, I was actually just able to switch my Stats script to one scriptable object based off this thread: https://www.pixelcrushers.com/phpbb/vie ... s&start=10 Seems more streamlined and scalable, so thanks as well for your answers here!

Had one quick question on tooltip integration from that thread, wasn't sure if I should add a reply there or here. I have everything working smoothly from this thread apart from the Get(Text) modifier description appearing in a tooltip rather than the default dialogue text. You alluded that this would be possible but I haven't been able to figure out how to change the AdvancedSkillCheckExample script to accommodate this.

Again, really appreciate the help you've already given me!
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Lua Functions for Stats and Modifiers

Post by Tony Li »

Take a look at the Hover Response Button Example (direct download) on the Extras page.

It shows the dialogue entry node's Description field as the tooltip. But you can use the value of GetText() instead.
Post Reply