Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ethan D on Thu 21/04/2011 00:42:38

Title: Problem with Custom Remove from list function[Solved but not sure how]
Post by: Ethan D on Thu 21/04/2011 00:42:38
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


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!
Title: Re: Problem with Custom Remove from list function[Solved but not sure how]
Post by: Ethan D on Thu 21/04/2011 04:58:09
Well, I've got it solved but I'm not entirely sure how...


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?