[SOLVED] Add and evaluate conditions at runtime
Posted: Sun Jun 16, 2024 10:56 am
Hi.
I'm struggling with what I can only assume is a fringe need. I want to add conditions to my Dialogue Entries at runtime.
I've managed to actually add the LUA logic to the conditions field, but when running the conversation for the first time these don't get evaluated. Only by exiting play-mode and re-entering does the conditions get evaluated.
Summary:
* I add conditions at runtime (through a method subscribing to: DialogueManager.instance.conversationStarted)
* The condition is a Lua function
* The runtime added conditions are not evaluated even though the text is clearly visible and the red "?" symbol are added to the Dialogue Entry Nodes
* I keep the conditions (for testing purposes) after exiting play-mode.
* If I enter play-mode again and enter the same conversation the now already added conditions are evaluated and the correct dialogue entry is selected.
This method was part of a larger evaluation of the system, and might not find its way into the final implementation - but I would like to check if anyone knows if this feature can be made to work?
Can I force some kind of refresh of the conversation?
Here's a snippet of the code for clarity:
I'm struggling with what I can only assume is a fringe need. I want to add conditions to my Dialogue Entries at runtime.
I've managed to actually add the LUA logic to the conditions field, but when running the conversation for the first time these don't get evaluated. Only by exiting play-mode and re-entering does the conditions get evaluated.
Summary:
* I add conditions at runtime (through a method subscribing to: DialogueManager.instance.conversationStarted)
* The condition is a Lua function
* The runtime added conditions are not evaluated even though the text is clearly visible and the red "?" symbol are added to the Dialogue Entry Nodes
* I keep the conditions (for testing purposes) after exiting play-mode.
* If I enter play-mode again and enter the same conversation the now already added conditions are evaluated and the correct dialogue entry is selected.
This method was part of a larger evaluation of the system, and might not find its way into the final implementation - but I would like to check if anyone knows if this feature can be made to work?
Can I force some kind of refresh of the conversation?
Here's a snippet of the code for clarity:
Code: Select all
private bool HeuristicCheck(double id) {
Debug.Log($"ConditionCheck for {id}");
int conversationID = DialogueManager.currentConversationState.subtitle.dialogueEntry.conversationID;
DialogueEntry entry = db.GetDialogueEntry(conversationID,(int)id);
return Field.LookupInt(entry.fields,"Weight") == allowedWeight;
}
private void Started(Transform _) {
Debug.Log("started...");
DialogueManager.Pause();
int conversationID = DialogueManager.currentConversationState.subtitle.dialogueEntry.conversationID;
List<DialogueEntry> allEntriesInConversation = db.GetConversation(conversationID).dialogueEntries;
Debug.Log($"this conversation has {allEntriesInConversation.Count} entries");
foreach (var entry in allEntriesInConversation) {
int weight = Field.LookupInt(entry.fields,"Weight");
if(weight > allowedWeight) {
allowedWeight = weight;
}
if (entry.outgoingLinks.Count != 0 && string.IsNullOrEmpty(entry.DialogueText)) continue;
string conditionLUA = string.IsNullOrEmpty(entry.conditionsString) ? "" : " and ";
string luaCode = $"{nameof(HeuristicCheck)}({entry.id})";
conditionLUA += luaCode;
if (entry.conditionsString.Contains(luaCode)) continue;
entry.conditionsString += conditionLUA;
Field.SetValue(entry.fields,"temp_condition_lua",conditionLUA);
}