Classes and Dialgue question

So far the few times I’ve posted on here I’ve been able to sort out the problems I’ve ran into. This time though I’m not so sure I’ll get that lucky. So here goes. I’ve found a very nice script on the forums here for doing convos. I am of course doing this for learning purposes. i get scripts and tear them apart to see what was done and why. Here is my convo script I have.

var nodes                : Array = new Array();
    var currentNode          : int = 0 ;
    var DialogueButtons      = false;
    var dialogueSwitch       :int;
	var characterTalking     :Texture2D;
	var characterAvatar      :Texture2D;
	var textureBackground3   :Texture2D;
	   	
	class ConvNode 
	{
        var prompt : String;
        var options: Array = new Array();
    }
     
    class OptionButton 
	{
        var reply : String;
        var effects : Array = new Array();
        var link : int;
	}
     
function Start () 
{
		//node 0
        nodes[0] = new ConvNode();
        nodes[0].prompt = "Ah, Avatar! Yes, I'd  know you anywhere; you look just like the tapestry. So, you have arrived at last!";
        nodes[0].options[0] = new OptionButton();
        nodes[0].options[1] = new OptionButton();
        nodes[0].options[2] = new OptionButton();
        nodes[0].options[0].reply = "Who are you.";
        nodes[0].options[0].link = 1;
        nodes[0].options[1].reply = "I need to speak with Lord British.";
        nodes[0].options[1].link = 2;
        nodes[0].options[2].reply = "I should be going.";
        nodes[0].options[2].link = 3;
        
		// node 1
        nodes[1] = new ConvNode();
        nodes[1].prompt = "My name is Hennington, I'm Lord British's seneschal; I run his daily affairs. What he knows, he tells me, I then make sure that the people know of your progress.";
        nodes[1].options[0] = new OptionButton();
        nodes[1].options[1] = new OptionButton();
        nodes[1].options[0].reply = "Can I ask you some questions?";
        nodes[1].options[0].link = 3;
        nodes[1].options[1].reply = "I need to speak with Lord British.";
        nodes[1].options[1].link = 2;
        
		//node 2
        nodes[2] = new ConvNode();
        nodes[2].prompt = "He has been expecting you for quite some time. You should go find him right away, he needs to talk to you. It's very important!";
        nodes[2].options[0] = new OptionButton();
        nodes[2].options[0].reply = "Alright, farewell.";
        nodes[2].options[0].link = 4;
        
		//node 3
        nodes[3] = new ConvNode();
        nodes[3].prompt = "Certainly not! You need to talk to Lord British. It's very important, now go!";
        nodes[3].options[0] = new OptionButton();
        nodes[3].options[0].reply = "Alright, farewell.";
        nodes[3].options[0].link = 4;
        
		//node 4
        nodes[4] = new ConvNode();
        nodes[4].prompt = "Go on, go talk to Lord British.";
        nodes[4].options[1] = new OptionButton();
        nodes[4].options[1].reply = "Goodbye.";
		nodes[3].options[0].link = 5;
}
     
     
function OnGUI () 
{
        switch(dialogueSwitch)
		{
            case 5:
				guicharacters = true;
                DialogueButtons = true;
                break;
        }
     
        //character box
        if (guicharacters == true) 
		{
            //avatar box
            GUI.Box (Rect (Screen.width * 0.02, Screen.height * 0.02, Screen.width * 0.13, Screen.height * 0.21), characterTalking);
            GUI.Label (Rect (Screen.width * 0.03, Screen.height * 0.04, Screen.width * 0.145, Screen.height * 0.185), characterAvatar);
            //speech box
            GUI.Box (Rect (Screen.width * 0.16, Screen.height * 0.02, Screen.width * 0.82, Screen.height * 0.17), "Speech");
            [B]GUI.Label (Rect (Screen.width * 0.17, Screen.height * 0.05, Screen.width * 0.80, Screen.height * 0.17), nodes[currentNode].prompt);[/B]
           
        }
     		
		//dialogue buttons location + toggle
        if (DialogueButtons == true) 
		{
         for (var i:int = 0; i< nodes[currentNode].options.length; i++) 
			{   
             [B]if (GUI.Button(Rect(Screen.width * 0.05, Screen.height * (0.83 + 0.04 *i), Screen.width * 0.90, 20), nodes[currentNode].options[i].reply)) [/B]
				{
                    for (var j:int = 0; j< nodes[currentNode].options[i].effects.length; j++) 
					{
                        handleeffects(nodes[currentNode].options[i].effects[j]);
                    }
                    currentNode = nodes[currentNode].options[i].link;
					break;
                }
			} 
        }
}
     
       
function handleeffects(input:String):void 
{
    print(input);
    switch (input) 
	{
     case "effect1":
     break;
    }
}

The lines 88 and 97 keep giving me the following error: ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count. Parameter name: index 5

I’m having a problem wrapping my head around classes and inheritance. And i have read almost everything I could find. Another thing that I have yet to figure out is how i could set a variable by pressing the option button? Anyway if anyone has some insight I’d appreciate it. I’m gonna keep reading and see if i can figure this out. Once again thanks to anyone who can help me out with this. The script works fine until i get to the end of the conversation…

…and yes, that is some dialogue straight out from Ultima 9 :slight_smile:

So i guess its only happening after you click “goodbye” on the last dialogue
at this point, the button sets currentNode to 5, then the gui block from 92 to 106 is trying to display nodes[currentNode], and you only have 5 nodes (0 to 4)

yes that’s what I figured was happening i’m just not sure how to keep it from happening. If I could figure out how to set a bool to break out of the cycle I would but haven’t had any luck.

So does anyone have any insight to what would be a good spot for a variable to set? I’ve been toying with it and with careful planning I can guide the conversation but there is too much linearness to it. Almost like there is no depth to the conversation.