Page 1 of 1

Stat checks

Posted: Mon May 29, 2023 1:26 pm
by leftarmstrong
Hi there,

Just bought this - absolutely love it already! Thanks for the great tutorial videos and support.

I'm currently working through some project ideas (and I'm fairly new to Unity too, but I'm trying!). I was watching the Conversation Conditions video, and it explained what it did really well, but I have a follow-up question. Around the 1:04 mark, you had a variable. Can I add an existing variable from my Player script, for instance, or a script outside of Dialogue System?

Basically:
1. Can I add variables from outside DS into DS?
2. Can I access variables from inside DS outside of it?
3. How robust is it, and is there documentation?

Thank you so much! I found the four-year-old video dealing with Lua scripts, but that didn't seem applicable here.

P.S. Or is that Lua applicable? LOL. Does DS only know Lua and not C#?

Re: Stat checks

Posted: Mon May 29, 2023 3:10 pm
by Tony Li
Hi,

Lua can know C#. See: Register C# With Lua. For a C# variable, you'd register get and set methods.

You may also be interested in: How To: Do Skill Checks in Conversations

Re: Stat checks

Posted: Mon May 29, 2023 7:58 pm
by leftarmstrong
Tony Li wrote: Mon May 29, 2023 3:10 pm Hi,

Lua can know C#. See: Register C# With Lua. For a C# variable, you'd register get and set methods.

You may also be interested in: How To: Do Skill Checks in Conversations
Hi Tony,

Thanks for the quick response. So if I had a C# public variable on my Player script, let's say, I'd follow the Starter Template Script for Custom Lua Functions and use one of the allowed data types? That seems like the only way?

I'll check out that article/package as well, and I'll review the video too. Little daunting but I think I get it now!

I'll give an example of what I'm trying to accomplish if it helps:

- Depending on a response in a *conversation, I want to subtract or add to a particular skill. Then, I want to use that skill number to determine dialogue options later.

Re: Stat checks

Posted: Mon May 29, 2023 9:41 pm
by Tony Li
Hi,

You can't register C# variables directly to Lua. You have to write C# methods and register those. For example, say you have a variable named "intimidate" that represents the player's intimidation skill. Don't register the intimidate variable. Instead, write methods to get and set the variable's value:

Code: Select all

public int intimidate;

public double GetIntimidateSkill() { return intimidate; }

public void SetIntimidateSkill(double value) { intimidate = value; }
And register those methods:

Code: Select all

Lua.RegisterFunction(nameof(GetIntimidateSkill), this, SymbolExtensions.GetMethodInfo(() => GetIntimidateSkill()));
Lua.RegisterFunction(nameof(SetIntimidateSkill), this, SymbolExtensions.GetMethodInfo(() => SetIntimidateSkill(0)));
Then in your conversations you can use those methods. For example, this option will only be available if the player has an intimidate skill of 20 or higher:
  • Menu Text: Intimidate the shopkeeper.
  • Conditions: GetIntimidateSkill() >= 20

Re: Stat checks

Posted: Tue May 30, 2023 6:53 pm
by leftarmstrong
Hi Tony,

OH. Oh, I get it now. Thank you so much for the explanation. I appreciate it, you, and the product!

Re: Stat checks

Posted: Tue May 30, 2023 6:55 pm
by Tony Li
Thanks! Glad to help.