This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I'm trying to make an inventory system like Pokémon (every item shown in a list). I just don't know how to add labels and textures for every new item that's added.
How can I do this?

If it helps, the items are being saved in an array.

in Engine by (56 points)

Are you referring to a VBoxContainer? If so, you add your Control nodes as children to the VBoxContainer.

Yes. Manually, that's the idea. But how do I make it so the code can add a new control for every new item got?

have you tried instancing a "control" scene into the vbox node?

1 Answer

0 votes
Best answer

Your question is a bit sparse on details but this should give you an idea anyways:

extends VBoxContainer

var items = [
    { "texture": "res://apple.png", "name": "Apple"}, 
    { "texture": "res://banana.png", "name": "Banana"}
]

func open_Inventory():
    for item in items:
        var item_row = HBoxContainer.new()

        var item_image = TexureRect.new()
        item_image.texture = load(item.texture)
        item_row.add_child(item_image)

        var item_name = Label.new()
        item_name.text = str(item.text)
        item_row.add_child(item_name)

        add_child(item_row)

    show()

func close_inventory():
    for item in get_children():
        item.queue_free()

    hide()
by (10,634 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.