Accessing Variables from within C# Scripts
Accessing Variables from within C# Scripts
Really sorry if there is already a post that discusses this but I can't find anything on this and I'm lost for what to do...Can I access my Dialogue Databases through C# code? or do I have to learn Lua and start writing Lua scripts?
Re: Accessing Variables from within C# Scripts
Hi,
You can use the DialogueLua C# functions. For example, if you've defined a Number variable "Score" in your dialogue database, you can get its value in a C# script with this code:
You can use the DialogueLua C# functions. For example, if you've defined a Number variable "Score" in your dialogue database, you can get its value in a C# script with this code:
Code: Select all
using PixelCrushers.DialogueSystem; // Put at top of script to access Dialogue System stuff.
...
int score = DialogueLua.GetVariable("Score").AsInt;
Re: Accessing Variables from within C# Scripts
Thanks for the quick reply! If you can, can you point me somewhere where I can learn more about getting different kinds of data from the database through C#? I find a lot on how to handle the GUI's and all, but I'm having a really hard time finding anything on the Quest system and the quest system video only seems to scratch the surface.
Re: Accessing Variables from within C# Scripts
Hi,
Here are the API reference pages:
- Quest management: QuestLog
- Database actors, items, and variables: DialogueLua
Here are some commonly-used methods in QuestLog:
Here are some commonly-used methods in DialogueLua:
At runtime, dialogue database information that can change (such as variable values) are put into Lua. You can get other information, such as the Dialogue Text of dialogue entry nodes, by accessing DialogueManager.MasterDabase. (The DialogueManager class itself has a lot of useful functions.) Here's an example of logging all dialogue texts:
Here are the API reference pages:
- Quest management: QuestLog
- Database actors, items, and variables: DialogueLua
Here are some commonly-used methods in QuestLog:
Code: Select all
QuestState state = QuestLog.GetQuestState("My Quest");
QuestLog.SetQuestState("My Quest", QuestState.Active);
int numEntries = QuestLog.GetQuestEntryCount("My Quest");
QuestState state = QuestLog.GetQuestEntryState("My Quest", 1);
QuestLog.SetQuestEntryState("My Quest", 1, QuestState.Success);
string[] QuestLog.GetAllQuests(QuestState.Success | QuestState.Failure);
Code: Select all
bool DialogueLua.GetVariable("My Variable").AsBool;
DialogueLua.SetVariable("My Variable", true);
int age = DialogueLua.GetActorField("Player", "Age").AsInt;
DialogueLua.SetActorField("NPC 1", "Age", 21);
Code: Select all
foreach (var conversation in DialogueManager.MasterDatabase.conversations) {
Debug.Log("Conversation: " + conversation.Title);
foreach (var dialogueEntry in conversation.dialogueEntries) {
Debug.Log("Dialogue Text: " + dialogueEntry.DialogueText);
}
}