[HOWTO] How To: Tie External Data To Dialogue Database
Posted: Wed Jan 27, 2021 9:34 am
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:
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:
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:
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;
Code: Select all
Lua.Run("Actor['Narrator'] = { Name='Narrator' }"); // Create a table for a new actor named Narrator.
DialogueLua.SetActorField("Narrator", "IsPlayer", false);
Code: Select all
void Awake()
{
Lua.RegisterFunction("IsInvulnerable", this, SymbolExtensions.GetMethodInfo(() => IsInvulnerable()));
}
bool IsInvulnerable()
{
return someRow.Get<bool>("Invulnerable");
}