[HOWTO] How To: Tie External Data To Dialogue Database

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

[HOWTO] How To: Tie External Data To Dialogue Database

Post by Tony Li »

A user had a question about tying data in their BG Database to the Dialogue System at runtime, including putting info from BG Database into the Dialogue System's Lua environment. Here's some info for others who may need to do the same:

The Dialogue System has a class for that: DialogueLua.

Here's an example of getting and setting a variable:

Code: Select all

  int score = row.Get<int>("Score");
  DialogueLua.SetVariable("Score", score);
  s = DialogueLua.GetVariable("Score").asInt;
Actors are stored in Lua tables (aka dictionaries in C#). Actor tables can have any number fields, but the two important ones are "Name" and "IsPlayer". In addition to DialogueLua, you can also use the Lua class directly, and mix and match:

Code: Select all

  Lua.Run("Actor['Narrator'] = { Name='Narrator' }"); // Create a table for a new actor named Narrator.
  DialogueLua.SetActorField("Narrator", "IsPlayer", false);
If you don't want to put some data into the Dialogue System's Lua environment, but instead have your conversations access them directly from BG Database, you can write some C# methods to access the BG Database data. Then register those methods with Lua so you can call them in conversations' nodes. Example:

Code: Select all

  void Awake()
  {
    Lua.RegisterFunction("IsInvulnerable", this, SymbolExtensions.GetMethodInfo(() => IsInvulnerable()));
  }
  bool IsInvulnerable()
  {
      return someRow.Get<bool>("Invulnerable");
  }
bgdbLuaFunc.png
bgdbLuaFunc.png (4.32 KiB) Viewed 453 times
Post Reply