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?
Ã, Ã, Ã,Â
Where exactly do you have this code placed in?
Are you sure you have an item selected when you are pressing the button?
Yes, I have already checked
The Error comes up when I press the button
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);
It seems to me that you should still check...
if (list.SelectedIndex != -1) list.RemoveItem(list.SelectedIndex);
Should work fine.