Hi there. I have troubles creating a quest listbox.
Two quests:
- dig a grave
- find a cadaver
If he will first get the quest "dig a grave" it will be number "1" in the Listbox, but if he will get it after he got the quest "find a cadaver" than it will be number "2"... Now since numbers of these quests in the listbox can be different, how can I remove a specific item from the listbox? I cant. I can only remove it by its number :f ( not by text ("dig a grave").
I have tried this (found in one old thread, but it didnt work where marked)
function AddQuest (String text) {
quests.InsertItemAt (0, text);
}
function LoseQuest (String text) {
int Temp;
while (Temp < quests.ItemCount) {
if (quests.Items == text) { //DIDNT WORK
Temp = quests.ItemCount;
}
Temp ++;
}
}
I would prefer the easiest method if possible. Thanks a million.
Gepard
try change
if (quests.Items == text){
to
if (quests.Items[Temp].CompareTo(String.Format("%s",text), false) == true) {
Not working... Although it was able to compile the script :D Anyway. I would prefer something much less complicated... if there is such a thing. Simply remove the listbox item by its "name" not number...
Well, I read the manual and it states that CompareTo returns an int, not a bool, so leasson learned: Read the manual.
And you're code seem to compleatly lack anything that actually removes the item when it's found, so even if it do find the correct one, it doesn't remove it.
So because I'm such a nice man, here you go:
void LoseQuest(String text){
int p;
while (p < ListBox1.ItemCount){ //Change ListBox1 with the name of your listbox
if (ListBox1.Items[p].CompareTo(text, false) == 0){ //Change ListBox1 with the name of your listbox
ListBox1.RemoveItem(p); //Change ListBox1 with the name of your listbox
return;
}
p ++;
}
}
I belive that if you only had read in the manual about listbox items, then you should have been able to solve this your self.
[Edit]
Sounded a bit harsh there, not what I intended.
Works great :f ) Sometimes the most obvious things just do not get your attention. Thanks for the help and btw. I am one of the few people that actually read the manual :f ) Thanks again!