Indexing in an ItemList
Asked Answered
S

2

0

I'm working on my Inventory UI. So far, I can populate an ItemList with various items and get it to display these item names as desired. Where I'm tripping up is the item quantity. Here is the section in question:

func PopulatePanel():
	var counter = loot_dic.size()
	while counter != 0:
		var icon = load("res://Scenes/Menus/Inventory/Icons/" + InventoryImport.loot_data[location]["Item" + str(counter) + "Name"] + ".svg")
		var name = InventoryImport.loot_data[location]["Item" + str(counter) + "Name"]
		loot_list.add_item(name, icon, true)
		item_index = loot_list.get_index() ### This seems to be where it's getting hung up ###
		quantity = loot_dic[counter][1]
		loot_list.set_item_tooltip(item_index, str(quantity))
		counter = counter - 1
		print(quantity)

func _on_LootList_item_selected(index):
	var name = loot_list.get_item_text(index)
	var item_quantity = loot_list.get_item_tooltip(item_index)
	loot_name.set_bbcode("[center]" + name + " - " + str(item_quantity) + "[/center]")

What I think is supposed to happen is that for each item generated, the quantity will be stored in that item's tooltip. Set the tooltip, get the tooltip, all is well.
Quantities will print in the Output, but when implemented, only the first item will have a quantity, and it's usually wrong unless it's the only item. Sometimes I will tweak it and it ends up displaying the same quantity for all of them. I figured the tooltip was a safe, already-included option to use versus creating a new label and yadda yadda. What am I missing?

Shoring answered 14/1, 2023 at 0:16 Comment(0)
H
0

Did you make the code yourself or did you copy it?

If you made it have your declared the var loot_list?
Second in the while loop are you declaring the var icon and var name as variables or are them lambda function? They look kind busy.

Hillis answered 14/1, 2023 at 15:2 Comment(0)
S
0

Hillis

It's from Game Development Center's Advanced Inventory tutorial. The difference is that I am modifying it to fit an ItemList (versus buttons/labels like he uses), so my PopulatePanel is different than his PopulatePanel.
As for Icon and Name, they're set up as variables, though you could make the argument that Icon is actually a lambda. But seeing how I'm not having any problems loading the item icon or the name, I haven't given it much thought.

Shoring answered 14/1, 2023 at 22:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.