Page 1 of 1

Start a script from a node

Posted: Sun Feb 03, 2019 8:19 am
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?

Re: Start a script from a node

Posted: Sun Feb 03, 2019 8:39 am
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

Re: Start a script from a node

Posted: Sun Feb 03, 2019 9:25 am
by rolfh
Thank You! So much easier with an example.
What about the other way. Can a script start a conversation?

Re: Start a script from a node

Posted: Sun Feb 03, 2019 9:46 am
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.