Quitting the dialogue when array is out of bounds

Maby this would be a nob question. But what I would like implement is to quit the dialogue when the player is at the end of the Dialoguenode. Currently in the dialogue course to quit the dialogue, the player has to click on the click button in order to close the dialogue. I would like to make a condition if the player is at the end of the node, then quit the dialogue.

public void Quit()
        {
            currentDialogue = null;
            currentNode = null;
            isChoosing = false;
            onConversationUpdated();
        }

public void Next()
        {
            int numPlayerResponses = currentDialogue.GetPlayerChildren(currentNode).Count();
            if (numPlayerResponses > 0)
            {
                isChoosing = true;
                onConversationUpdated();
                return;
            }

            DialogueNode[] children = currentDialogue.GetAIChildren(currentNode).ToArray();
            int randomIndex = UnityEngine.Random.Range(0, children.Count());
            currentNode = children[randomIndex];
            onConversationUpdated();
            
            if (children.Last())
            {
                Quit();
            }
        }

        public bool HasNext()
        {
            return true;
            //return currentDialogue.GetAllChildren(currentNode).Count() > 0;
        }

Inserting the snippet I’ve put above should make this happen.

Hi Brian,

Thnx for your comment. I used the snippet you’ve sended me. Still got some errors. With count == 0 and button that din’t work. After placing Count() == 0 and add currentNode = children[randomIndex]; after if statement it worked thank you alot. I’'l leave a snippet for any one else who want to emplement this.

DialogueNode[] children = currentDialogue.GetAIChildren(currentNode).ToArray();
            if (children.Count() == 0)
            {
                Quit();
                return;
            }
            int randomIndex = UnityEngine.Random.Range(0, children.Count());
            currentNode = children[randomIndex];
            onConversationUpdated();

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms