+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.

asked Jul 3 in Engine by Lfzinho (29 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

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)

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



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

answered Jul 15 by njamster (8,768 points)
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 How to use this Q&A? before posting your first questions.