Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: James (Aka: The Geek) on Thu 13/07/2006 18:52:39

Title: Delete Selected Item
Post by: James (Aka: The Geek) on Thu 13/07/2006 18:52:39
I need my game to delete the item selected on the listbox when the user presses a button.

I have tried something simalar to this:

Ã,  Ã, int number = list.SelectedIndex;
Ã,  Ã,  Ã,  Ã,  list.RemoveItem(number);

When I run the game it says invalid index ???

Does anybody have any suggestions?
Ã,  Ã,  Ã, 
Title: Re: Delete Selected Item
Post by: Ubel on Thu 13/07/2006 19:00:18
Where exactly do you have this code placed in?

Are you sure you have an item selected when you are pressing the button?
Title: Re: Delete Selected Item
Post by: James (Aka: The Geek) on Thu 13/07/2006 19:12:04
Yes, I have already checked
The Error comes up when I press the button
Title: Re: Delete Selected Item
Post by: Ubel on Thu 13/07/2006 19:39:29
Hmm, tricky. The manual says:
QuoteNOTE: Calling this function causes other items in the list to get re-numbered, so make sure you don't keep around any references from ListBox.SelectedIndex and related functions while using this command.
So this might not work properly. But try this:

Try putting this on top of your global script:

int listboxnumber;


Then this into your ListboxSelectionChanged script:

listboxnumber=list.SelectedIndex;


Then this into on_key_press:

list.RemoveItem(listboxnumber);
Title: Re: Delete Selected Item
Post by: monkey0506 on Thu 13/07/2006 19:52:45
It seems to me that you should still check...

if (list.SelectedIndex != -1) list.RemoveItem(list.SelectedIndex);

Should work fine.