dialogue/text box list not working as intended

first of all, here’s the code - so i have an interact button which if ui text box is visible- goes to change the text to whatever i set it to - and recently i wanted to create a list so i could add several texts at once, and for each click move on to the next stored text and remove the one just read - however, this doesnt seem to work as intended. Any input?

public void nextBodyText()
    {
        if (isCurrentlyVisible)
        {
            if (bodyTextList.Count > 0)
            {
                
                bool hasGrabbedText = false;
                foreach (string tempString in bodyTextList)
                {
                    Debug.Log(tempString);
                    //This isnt gonna work later on, we need to fix..
                    if (!hasGrabbedText) {
                        displayBodyText = tempString;
                        hasGrabbedText = true;
                    }
                    //displayBodyText +"

"+ tempString;
}
bodyTextList.RemoveAt(1);
}
else
{
setBodyText(“Nothing.”);
nextBodyText();
}
}
else
{
Debug.Log(“Dialogue Box is currently Hidden”);
}
}
public bool checkIfVisisble()
{
bool tempVis;
tempVis = isCurrentlyVisible;
Debug.Log("Dialogue box is visible: "+tempVis);
return tempVis;
}
public void setDialogueBoxVisible()
{
isCurrentlyVisible = true;
}
public void setDialogueBoxHidden()
{
isCurrentlyVisible = false;
}
public void setBodyText(string tempText)
{
Debug.Log("Added to text list: "+tempText);
bodyTextList.Add(tempText);
//displayBodyText = tempText;
}

i included all the relevant methods. Just setting the text works perfectly, the problem arrives when i try to move on to the next text. Its as if it doesnt get added to the list, but as you can see, it clearly does.


Another thing is - it does actually show the FIRST and ONLY the first thing to be displayed- and then never again, does it display anything else, i.e if i put nothing and press interact, it displays “nothing” if i do a battle thing it says “Battle has started” - whatever is the first to be inputted is what it shows - and the list never seems to have anything other than that, added to it. Seems strange to me, im well versed in using lists in java for my objects, but this doesnt seem to work.

I would just use “first item in list” but it gives me an error, which is why i had to do a for each loop.

You could replace

                 bool hasGrabbedText = false;
                 foreach (string tempString in bodyTextList)
                 {
                     Debug.Log(tempString);
                     //This isnt gonna work later on, we need to fix..
                     if (!hasGrabbedText) {
                         displayBodyText = tempString;
                         hasGrabbedText = true;
                     }
                     //displayBodyText +"

"+ tempString;
}
bodyTextList.RemoveAt(1);

For this

if ( bodyTextList.Count > 0 ){
    displayBodText = bodyTextList[0];
    bodyTextList.RemoveAt(0);
}

What you were doing wrong was that you were removing the second element, instead of the first. An extraclarification from @Harinezumi :

All collections (arrays, List, Set, Queue, etc.) index starting with 0, so bodyTextList.RemoveAt(1) removes the second element in the array.
You possibly didn’t run into this, but when you only have 1 element left in your bodyTextList, calling RemoveAt(1) on it will through an indexing exception.