If Click Node Then

Announcements, support questions, and discussion for the Dialogue System.
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

If Click Node Then

Post by Barto1983 »

Hello I have done the tutorial Quickstart.

Now i have many Nodes.

My question is the following:

How can I react to the single clicked node

for example


NPC: "Hallo how are you"

Player Answer A: "Thx i'm fine"
Player Answer B: "Very bad"

if Answer A then{ dosomethingA}
For Example: Player.setMoney += 300;
if Answer B then {dosomethingB}
For Example: "Game Over"

A small example would be perfect

Excuse me for the basic questions, but somehow the documentation is so great. I do not see the forest in front of loud trees.

Thank you very much
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post by Tony Li »

Hi,

Every dialogue entry node has three types of "control" fields: Conditions, Script, and Sequence.

Conditions field:
You can use the Conditions field to make a dialogue entry node available or not available. For example*:
  • NPC: "Hallo how are you"
    • Player Answer A: "Thx i'm fine"
    • Player Answer B: "Very bad"
    • Player Answer C: "I'm rich!"
      Conditions: Player.money > 1000
The response menu will only show Player Answer C if the player has more than 1000 money.

Script field:
You can use the Script field to add actions to a dialogue entry node, such as giving money. For example*:
  • NPC: "Hallo how are you"
    • Player Answer A: "Thx i'm fine"
      Script: Player.money += 300;
    • Player Answer B: "Very bad"
      Script: Game over
* However, the examples above will not work as-is. I provided them above as a conceptual introduction to the Conditions and Script fields. The Conditions and Script fields provide a special interface called "Lua". Lua is actually a scripting language, which gives you powerful control over conversations.

To work with Dialogue System data, such as variables you've defined in the Variables section of the Dialogue Editor, you don't have to type anything. You can use the point-and-click Lua Wizards.

On the other hand, if you want Lua to reach outside of the Dialogue System to your own scripts, you can register your C# methods with Lua. This is what the third party integration packages do. For example, the Opsive Third Person Controller integration registers Lua functions to set the player's health, give or take items, etc.

If "Player.money" is a value in your own script, register a C# method with Lua so you can access it in the Script field.


Sequence field:
The Sequence field lets you run a cutscene sequence.

The Conditions and Script fields are mostly for data (e.g., check and change variable values). The Sequence field, on the other hand, is for changing what the player experiences -- for example, zooming the camera, or playing audio clips. The Dialogue System comes with a big library of built-in sequencer commands. However, you can also write your own custom sequencer commands. The example provided in the documentation adds a LoadLevel sequencer command that you can use to load a new scene during a conversation.
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

Re: If Click Node Then

Post by Barto1983 »

sry i dont Really understand?

"On the other hand, if you want Lua to reach outside of the Dialogue System to your own scripts, you can register your C# methods with Lua. This is what the third party integration packages do. For example, the Opsive Third Person Controller integration registers Lua functions to set the player's health, give or take items, etc."

Im must buy this??:Opsive Third Person Controller

So I can realize my idea ??
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post by Tony Li »

No. You do not have to buy anything else.

I'm sorry I was unclear. Let's restart the discussion from the beginning.

You wrote this:
Barto1983 wrote:if Answer A then{ dosomethingA}
For Example: Player.setMoney += 300;
What is "Player.setMoney"? Where does it come from?
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

Re: If Click Node Then

Post by Barto1983 »

public static class Player {

public static int money = 300;
}

it a normal static c# class


if Answer A then{ dosomethingA}
For Example: Player.money += 300;

I will add 300 to Player.money if the Answer is A
or Change Background Image or Close Game and so on

I search something like OnNodeEventClick(){
}
Attachments
Conv.PNG
Conv.PNG (55.07 KiB) Viewed 1414 times
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post by Tony Li »

Hi,

I'm going to be out of the office for a couple hours, but I'll send you an easy to follow example as soon as I get back.
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

Re: If Click Node Then

Post by Barto1983 »

Thank you very much
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: If Click Node Then

Post by Tony Li »

Here's an example scene: CustomLuaExample_2017-03-02.unitypackage

It's just like your conversation, except the "oh no" dialogue entry node's Script contains this:

Code: Select all

SetMoney(50 + GetMoney())
It uses functions "GetMoney" and "SetMoney". A new script PlayerLua.cs adds these functions. I added PlayerLua.cs to the Dialogue Manager.

PlayerLua.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class PlayerLua : MonoBehaviour {

    void OnEnable() {
        Lua.RegisterFunction("GetMoney", this, GetType().GetMethod("GetMoney"));
        Lua.RegisterFunction("SetMoney", this, GetType().GetMethod("SetMoney"));
    }

    void OnDisable() {
        Lua.UnregisterFunction("GetMoney");
        Lua.UnregisterFunction("SetMoney");
    }

    public double GetMoney() {
        return Player.money;
    }

    public void SetMoney(double amount) {
        Player.money = (int)amount;
    }
}
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

Re: If Click Node Then

Post by Barto1983 »

Hey thx you for you fast answer.

I will try it when iam at home.

Thx
Barto1983
Posts: 24
Joined: Thu Mar 02, 2017 8:52 am

Re: If Click Node Then

Post by Barto1983 »

Hi Tony Li I would like to thank you for the quick help.

That's what I call a great support.

Keep up the good work
Post Reply