Hi,
I'll suggest two completely different ways you can approach this.
Approach 1
First, you can hook into the Dialogue System's save system to save your list. Just add two methods, OnRecordPersistentData() and OnApplyPersistentData(). You can find an example with lots of instructional comments in Templates/Scripts/PersistentDataTemplate.cs. For example:
Code: Select all
using PixelCrushers.DialogueSystem;
List<string> conversations;
void OnRecordPersistentData()
{
string s = string.Join(";", conversations.ToArray());
DialogueLua.SetVariable("ConversationPool", s); // Save list in variable ConversationPool.
}
void OnApplyPersistentData()
{
string s = DialogueLua.GetVariable("ConversationPool").AsString;
conversations = new List<string>(s.Split(";"));
}
Similarly, you can register a C# method with Lua fairly easily. The Templates/Scripts/TemplateCustomLua.cs file has instructional comments. Example:
Code: Select all
using PixelCrushers.DialogueSystem;
void OnEnable()
{
Lua.RegisterFunction("AddConversation", this, SymbolExtensions.GetMethodInfo(() => AddConversation(string.Empty)));
}
public void AddConversation(string conversation)
{
conversations.Add(conversation);
}
Example of using this in a dialogue entry node:
- Dialogue Text: "You should talk with my friend Adam."
- Script: AddConversation("Adam")
Approach 2
However, you could take a
completely different approach to this whole thing. This approach doesn't use anything I just mentioned above. Instead, create a special conversation -- call it Master -- with a <START> node that links to every possible conversation (Adam, Bob, Charlie, etc.). (To link to another conversation, inspect the <START> node and from the Links to: dropdown select
(Another Conversation).)
Then put conditions on each of those conversations. For example, maybe the Charlie conversation's conditions require that the "Meet Angels" quest is successful. Or maybe the Bob conversation requires that a variable "Knows Bob" is true.
This means that at any given time the Master conversation will point to some amount of valid links to other conversations, depending on their conditions.
To get the list of currently-valid conversations, you'll need to create a
ConversationModel. Here's an example that logs all currently-valid conversations to the console:
Code: Select all
var model = new ConversationModel(DialogueManager.masterDatabase, "Master", null, null, false, null);
foreach (var response in model.firstState.npcResponses)
{
var conversation = DialogueManager.masterDatabase.GetConversation(response.destinationEntry.conversationID);
Debug.Log(conversation.Title);
}
This approach is nice because all the logic (apart from the ConversationMode code just above) is contained in the dialogue database using the regular Conditions and Script fields, without any custom code to hook into the save system or Lua.