ItemList showing deleted items

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fraggynator

I have a quest log showing active quests and am trying to remove a quest once it has been completed. But the quest log (specifically the itemlist showing the active quests) behaves a bit weird:

The quests are added by calling the add_quest() function, which works fine.

func add_quest():
var activequests = QM.Quests.ActiveQuests
if quest_act < activequests.size():
	$QuestList.add_item(activequests[quest_act])
	quest_act += 1
else:
	return

Without the removal, getting the second quest from the NPC just adds a new item with its proper description when pressed, as intended. However, when I implement the following remove_quest() function, things look strange to me:

func remove_quest(questname, questdesc):
if questname in QM.Quests.ActiveQuests:
	var removed_quest = QM.Quests.ActiveQuests.find(questname)
	QM.Quests.ActiveQuests.erase(questname)
	QM.Quests.QuestDescription.erase(questdesc)
	$QuestList.remove_item(removed_quest)
	$QuestDescription.text = ""
	quest_act -= 1

The item gets deleted properly (as verified with print statements for debugging), but when I open the quest log again after completing the quest, the item is still displayed. Of course when I click it, I get the error “Invalid get index ‘0’ (on base: ‘Array’).”
Selection function:

func _on_QuestList_item_selected(index):
var quest_description = QM.Quests.QuestDescription[index]
$QuestDescription.text = quest_description

However, if I complete Quest1 and then accept Quest2 (thus removing one and adding a new item), the quest log then still shows the item “Quest1”, but when selected displays the correct quest description for Quest2.

Does anyone have an idea what is going on here? The entire GUI is set to Process, so that shouldn’t be the issue.

One thing you could check: Is the index for the ActiveQuest the same as the QuestItemList in your remove function?

HashtagOrNah | 2021-05-14 19:26

Thanks.
Yes, the QM.Quests.ActiveQuests.find() returns 0 in my tests (as expected for the first quest) and when I use that variable for $QuestList.get_item_text(), I get the correct quest name back.

fraggynator | 2021-05-15 11:47