After working through and testing the Disjunctions and Conjunctions. Fixing an error I had and found the solution as another user had the same problem.
I now have an issue were my code is breaking with dialogue. I try to click the button of Sure how? for the foot cream quest but by clicking I cannot move to the next piece of dialogue so I cannot get the quest.
Following error: (Added details on each line of code in the scripts)
IndexOutOfRangeException: Index was outside the bounds of the array.
RPG.Dialogue.PlayerConversant.Next () (at Assets/Scripts/Dialogue/PlayerConversant.cs:99)
RPG.Dialogue.PlayerConversant.SelectChoice (RPG.Dialogue.DialogueNode chosenNode) (at Assets/Scripts/Dialogue/PlayerConversant.cs:82)
RPG.UI.DialogueUI+<>c__DisplayClass11_0.<BuildChoiceList>b__0 () (at Assets/Scripts/UI/DialogueUI.cs:75)
UnityEngine.Events.InvokableCall.Invoke () (at <6afd1274f120405096bc1ad9e2010ba6>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <6afd1274f120405096bc1ad9e2010ba6>:0)
UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)
PlayerConversant Code:
public void SelectChoice(DialogueNode chosenNode){
currentNode = chosenNode;
TriggerEnterAction();
isChoosing = false;
// onConversationUpdated(); // Only call onConversationUpdated() here if not calling Next().
Next(); // This is line 82
}
public void Next()
{
int numPlayerResponses = FilterOnCondition(currentDialogue.GetPlayerChildren(currentNode)).Count();
if (numPlayerResponses > 0)
{
isChoosing = true;
TriggerExitAction();
onConversationUpdated();
return;
}
DialogueNode[] children = FilterOnCondition(currentDialogue.GetAIChildren(currentNode)).ToArray();
int randomIndex = UnityEngine.Random.Range(0, children.Count());
TriggerExitAction();
currentNode = children[randomIndex]; // line 99
TriggerEnterAction();
onConversationUpdated();
}
``
DialogueUI Code:
``
private void BuildChoiceList(){
foreach (Transform item in choiceRoot)
{
Destroy(item.gameObject);
}
foreach (DialogueNode choice in playerConversant.GetChoices())
{
GameObject choiceInstance = Instantiate(choicePrefab, choiceRoot);
var textComponent = choiceInstance.GetComponentInChildren<TextMeshProUGUI>();
textComponent.text = choice.GetText();
Button button = choiceInstance.GetComponentInChildren<Button>();
button.onClick.AddListener(() =>
{
playerConversant.SelectChoice(choice); // Error line 75
});
}
}
This only came up after I fixed a null error with the commpletedQuest condition.
I found that answer here in case anyone else sees this post.
CompletedQuest1xwfe9j_gaODc1MjYwMDQ3LjE2NjcwOTI4ODY._ga_2C81L26GR9*MTY2Nzc3MjkzOC4yNi4xLjE2Njc3NzQyODkuMC4wLjA.
This error now is out of range so somehow after the null check the game now sees the button option as not within the range as at the end of the error it looks to be listing cashe problems.
I am guessing the condition and disjunction and conjunction setup is somehow effecting this since the error only came up after they were implemented unless I am missing an exit or enter action for the dialogue choice. But there should be an enter or exit action for the player dialogue as the quest giving is when the NPC responds to the player with the GiveQuest exit action.
I feel like I am on the right track with this start…but I also am not sure where to test.