0 votes

I am making a runner game which has weapons and i made a invantory system for the wepons. Then when i tested, the inventory GUI wasn't showing text and images that i procedurally loaded. The code looks like this

func update_inventory():
#clear to minor the chance of any duplicates
$"CanvasLayer/Main Menu/Inventory/Panel/weapons".clear()


# set inventory hud
for item in inventory.size():
    var itemimg = load("res://Images/Weapons/"+inventory[item]+".png")
    $"CanvasLayer/Main Menu/Inventory/Panel/weapons".add_item(inventory[item], itemimg , true)
    print("updated inventory")
    if $"CanvasLayer/Main Menu/Shop/Panel/weapons".items.find(inventory[item]):
        $"CanvasLayer/Main Menu/Shop/Panel/weapons".set_item_disabled(item, true)
Godot version 3.3.3
in Engine by (29 points)

I don't have an answer to your problem, but I can offer a suggestion for clearer code. The line for item in inventory.size(): can be changed to:

...
for item in inventory:
    var itemimg = load("res://Images/Weapons/" + item + ".png")
...

The elements in an array can be iterated over without having to get the size of the array. Hope that helps.

Have you checked the Output window for errors? You can't just call "load("png")".

Please log in or register to answer this question.

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.