Show collected items but not their prerequisites

Hi all,
I’m trying to create an item list that shows my collected items and NOT their prerequisites.

This my item dictionary for now.

const ITEMS = {
	"ring1": {
		"icon": "res://Items/Ring/ring_icon.png",
		"displayname": "Ring",
		"details": "Damage +5",
		"level": "Level: 1",
		"prerequisite": [],
		"type": "item"
	},
	"ring2": {
		"icon": "res://Items/Ring/ring_icon.png",
		"displayname": "Ring",
		"details": "Damage +5",
		"level": "Level: 2",
		"prerequisite": ["ring1"],
		"type": "item"
	},
	"ring3": {
		"icon": "res://Items/Ring/ring_icon.png",
		"displayname": "Ring",
		"details": "Damage +5",
		"level": "Level: 3",
		"prerequisite": ["ring2"],
		"type": "item"
	}
}

What does your code look like? What isn’t working about your script? What does “Show” mean in this context, are you using UI?

1 Like

Yes I am using UI.

This is in my Player’s code.

collected_items is a GridContainer.

func adjust_item_collection(item_upgrade):
	var get_item_displaynames = Dictionary.ITEMS[item_upgrade]["displayname"]
	var get_collected_item_displaynames = []
	for i in collected_items:
		get_collected_displaynames.append(Dictionary.ITEMS[i]["displayname"])
	if not get_item_displaynames in get_collected_item_displaynames:
		var new_item_container = itemContainer.instantiate()
		new_item_container.item_upgrade = item_upgrade

		collectedItems.add_child(new_item_container)

The itemContainer is a TextureRect with this code.

extends TextureRect

#var spell_upgrade = null
var item_upgrade = null

@onready var itemTexture = $ItemTexture
@onready var colorRect = $ColorRect
@onready var nameLabel = $ColorRect/Name
@onready var levelLabel = $ColorRect/Level
@onready var detailLabel = $ColorRect/Detail

func _ready():
	if item_upgrade != null:
		itemTexture.texture = load(Dictionary.ITEMS[item_upgrade]["icon"])
		nameLabel.text = Dictionary.ITEMS[item_upgrade]["displayname"]
		levelLabel.text = Dictionary.ITEMS[item_upgrade]["level"]
		detailLabel.text = Dictionary.ITEMS[item_upgrade]["details"]

func _on_mouse_entered():
	colorRect.visible = true

func _on_mouse_exited():
	colorRect.visible = false

I am reading this and I am still not quite sure what the problem is.
You have a functional Item-Compendium that lists items via itemID (which is ring1, ring2 etc) but you don’t want to show the prerequisite.
You don’t need to show it if you don’t want to?

Your code of the ItemContainer or Player don’t even use the prerequisite?

Maybe you meant that you want to FILTER your Dictionary.ITEMS for all items that have an empty prerequisite array? You can do that by using the filter method.

for itemID in Dictionary.ITEMS.keys():
   if Dictionary.ITEMS[itemID].prerequisite.is_empty():
      #do what you must

This is what happens in my inventory when I get Ring Level 1

And this is when I get Ring Level 2

I just want my RingLvl1 to not show when I get RingLvl2 :smiling_face_with_tear:

Sorry for my Bad English :grimacing: