If Click Node Then

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post by Tony Li »

Happy to help! If you have any questions about using or extending the example, just let me know.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: If Click Node Then

Post 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?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post 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
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: If Click Node Then

Post by timbecile »

I see how it's supposed to work now. Thanks a bunch!
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: If Click Node Then

Post 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?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post 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
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: If Click Node Then

Post 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?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post 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) {
    ...
}
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: If Click Node Then

Post by timbecile »

Thanks Tony! I've got it all sorted now.
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post by Tony Li »

Great! Glad to help.
Post Reply