Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CrazyMind |
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)
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.
Ertain | 2022-09-25 14:57
Have you checked the Output window for errors? You can’t just call “load(“png”)”.
SteveSmith | 2022-09-29 11:46