Problem with Custom Remove from list function[Solved but not sure how]

Started by Ethan D, Thu 21/04/2011 00:42:38

Previous topic - Next topic

Ethan D

Hello everyone,

The code below is supposed to cycle through the different response options in a custom dialog system I'm working on and then remove the one that matches with the string 'whattoberemoved' which is passed in the RemoveFromDialogList function.  However, when it matches at least one thing on the list it removes everything, I'm not sure why considering that I checked and it only executes the if function one time

Code: ags

function RemoveFromDialogList(const string whattoberemoved)
{ 
  while (scandialog <= DialogList.ItemCount)
  {
    
    if (whattoberemoved == DialogList.Items[scandialog])
    {
      DialogList.SelectedIndex = scandialog;
      DialogList.RemoveItem(DialogList.SelectedIndex);
      scandialog = 0;
      return;
    }
    scandialog++;
  }
}


I'm almost certain that I'm missing something stupid.

Thanks for any help!

Ethan D

Well, I've got it solved but I'm not entirely sure how...

Code: ags

function RemoveFromDialogList(const string whattoberemoved)
{ 
  while (scandialog <= DialogList.ItemCount)
  {
    if (whattoberemoved == DialogList.Items[scandialog])
    {
      DialogList.SelectedIndex = scandialog;
      DialogList.RemoveItem(DialogList.SelectedIndex);
      dialogcounter = dialogcounter - 1;
      scandialog = 0;
      return;
    }
    scandialog++;
  }
}
function GenerateDialogGUI()
{
  gDialog.Visible = true;
  gDialog.Y = 240-(dialogcounter*12);
  Wait(1);
}

function AddToDialogList(const string Responsechoice)
{
  DialogList.AddItem(Responsechoice);
  dialogcounter = dialogcounter + 1;
}


Interestingly, all I had to do was put a Wait(1); command after GenerateDialogGUI function and it works perfectly.  I'm not entirely sure why though.  Any thoughts?

SMF spam blocked by CleanTalk