Start a script from a node

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rolfh
Posts: 2
Joined: Sun Feb 03, 2019 8:13 am

Start a script from a node

Post by rolfh »

The doc is not so easy for a beginner. What I like to do is to start a method in one of my own c# script when the player has selected one of two nodes. How do I do that?
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Start a script from a node

Post by Tony Li »

Hi,

Use Lua.RegisterFunction() to make your C# script method available to the Dialogue System. Example:

Code: Select all

using PixelCrushers.DialogueSystem;
...
void Awake() {
    // Make your C# method available to the Dialogue System:
    Lua.RegisterFunction("WriteLog", this, SymbolExtensions.GetMethodInfo(() => WriteLog(string.Empty)));
}

void WriteLog(string message) { // This is your C# method.
    Debug.Log(message);
}
Then call it in your node's Script field:
  • Script: WriteLog("Hello world")
More info: Register functions
rolfh
Posts: 2
Joined: Sun Feb 03, 2019 8:13 am

Re: Start a script from a node

Post by rolfh »

Thank You! So much easier with an example.
What about the other way. Can a script start a conversation?
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Start a script from a node

Post by Tony Li »

Sure!

Use DialogueManager.StartConversation().

Pass it the conversation title. You can optionally also specify the actor & conversant GameObjects, and also a starting entry ID.
Post Reply