Page 2 of 2

Re: If Click Node Then

Posted: Fri Mar 03, 2017 3:25 pm
by Tony Li
Happy to help! If you have any questions about using or extending the example, just let me know.

Re: If Click Node Then

Posted: Mon Mar 12, 2018 11:04 pm
by timbecile
Hi Tony! I've been working with your Dialog system for a few months now. This was almost exactly what I was looking for!

I need to check to see if a player has a specific variable set to a certain value (ie if they have a certain skill) to allow a dialog node to appear. How would I check a value in the condition field? I'm assuming it would be similar to this thread, except using the condition field instead of the script field?

Re: If Click Node Then

Posted: Tue Mar 13, 2018 9:33 am
by Tony Li
Yes, that's it exactly. An earlier post in this thread has an example with two Lua functions: SetMoney() and GetMoney(). You can use GetMoney() in the Conditions field to check if the player has enough money:
  • Dialogue Text: "Sorry, you don't have enough money."
    Conditions: GetMoney() < 100
  • Dialogue Text: "I see you have enough money. Want to buy this?"
    Conditions: GetMoney() >= 100

Re: If Click Node Then

Posted: Wed Mar 14, 2018 9:27 pm
by timbecile
I see how it's supposed to work now. Thanks a bunch!

Re: If Click Node Then

Posted: Wed Mar 14, 2018 10:53 pm
by timbecile
ok, so I guess this is more complicated than I thought. Here is the scenario:

* Player has a certain amount of skills that can be promoted
* different NPCs teach different skills
* I need to check to see if the player has the same skill that the NPC teaches

The issue that I've been having is that multiple NPCs are registering the same LUA function and (I think) Lua is calling the wrong one.

Is that the case? I'm assuming that LUA isn't smart enough to know to call the function attached to the dialog's game object?

Re: If Click Node Then

Posted: Thu Mar 15, 2018 10:21 am
by Tony Li
It's a global Lua environment, not specific to each NPC.

There are a few ways you could handle this. Choose the one you prefer.



1. Add a different Lua function for each NPC or each skill. For example, add Lua functions such as:
  • GetWarriorSkill()
  • SetWarriorSkill()
  • GetMageSkill()
  • SetMageSkill(), etc.
and use it like this:
  • Dialogue Text: "I'm Wyld the Warrior. Want to learn level 2 warrior skills?"
    Conditions: GetWarriorSkill() < 2


2. Or pass the skill name as a string. So your Lua function might look like:

Code: Select all

double GetSkillLevel(string skillName) {
    return // (skill level of skill named by skillName)
}
and you'd use it like this:
  • Dialogue Text: "I'm Wyld the Warrior. Want to learn level 2 warrior skills?"
    Conditions: GetSkillLevel("Warrior") < 2


3. Or look at the value of an actor's custom field. For example, expand Wyld the Warrior's All Fields section, and add a custom field named "Skill Type" set to "Warrior". Then register Lua functions named GetNPCSkill() and SetNPCSkill(#) that check the current conversant's

Code: Select all

double GetNPCSkill() {
    string npcName = DialogueLua.GetVariable("ConversantIndex");
    string npcSkillName = DialogueLua.GetActorField(npcName, "Skill Type").AsString;
    return // (skill level of skill named by npcSkillName)
}
and you'd use it like this:
  • Dialogue Text: "I'm Wyld the Warrior. Want to learn level 2 warrior skills?"
    Conditions: GetNPCSkill() < 2

Re: If Click Node Then

Posted: Thu Mar 15, 2018 9:31 pm
by timbecile
Thanks for the help Tony! You rule.

all are great options, but I think passing the variable is the best idea. How many vars can you pass from Lua?

Re: If Click Node Then

Posted: Thu Mar 15, 2018 9:54 pm
by Tony Li
Like C#, you can pass as many as you want. For example, you could define a function "IsLevelMet" that accepts three parameters: class name, skill name, and minimum level:
  • Dialogue Text: "I see you are a master conjurer. Do you do birthday parties?"
    Conditions: IsLevelMet("Wizard", "Conjuration", 15)
On the C# side, the code might look like this:

Code: Select all

bool IsLevelMet(string className, string skillName, double minLevel) {
    ...
}

Re: If Click Node Then

Posted: Sat Mar 17, 2018 1:58 pm
by timbecile
Thanks Tony! I've got it all sorted now.

Re: If Click Node Then

Posted: Sat Mar 17, 2018 2:20 pm
by Tony Li
Great! Glad to help.