![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Daezr |
Hi!
I’m very new to Godot and I’m trying to understand how to efficiently use Dictionary to create an Inventory. I’m probably not even doing it right so please bear with me if my code is messy.
I’m trying to pick up an object from the scene store his ID then compare it to a list of ID in a Dictionary that is usd as a database to store Icon and text description for my items.
To put it simple I want to read through my Dictionnary to find a value equal to the value of the object I picked
Here’s the function to pick an object
func _pickObject():
if Input.is_action_just_pressed("Interact"):
if CanPick == true:
CollectibleObject.queue_free()
StoringID = CollectibleObject.ID
HasCollected = true
The problem is I cannot figure how to connect the Stored ID to the ID in the dictionary.
I am currently trying to do something like that
extends Node
var DicID = { "ObjectTest" : {
objectID = 1,
icon = "res://icon.png",
description = "This is a test object",
}
}
The problem is I can’t figure how to connect the Stored ID to the ID in the dictionnary.
I’m currently trying to do something like that
func _ready():
menu = get_node("Inventaire/Panel")
menu.hide()
ObjectToLoad = get_node("Database").DicID.keys()
func _AddingObject():
ObjectToAdd = get_node("Hero/Area2D").StoringID
var IDtoCompare = ObjectToAdd
print(IDtoCompare)
for ObjectToLoad in get_node("Database").DicID:
if ( ObjectToLoad == IDtoCompare)
#DoStuff #ERROR
That’s where I have my problem, it only return an error telling that I can’t compare my Dictionary value with an Int using ==.
I figured out I wasn’t doing the right the thing but I have no idea how to compare the object my character picked up to the ones stored in my Dictionary.
Sorry if I expressed myself badly, I’m looking to any kind of help, tutorial or anything.
Thanks in advance !