hay
i am new here and to godot , even though i tryed using it fro at least 5 years ago
latly i hade some free time , and decided to create a ps1 style game using godot 4 with the help of IA in guiding me
but some how i reached a limit where IA cant really explane what,s wrong with my file .
here is what i am trying to do .
i finished doing the basic movement system , and started on the inventory system .
the inventory system is simple , i have 4 category’s " weapons " keys " consumables " files"
i did everything with the AI guid , where when i run the game , the items are sopused to automaticly bee added to my inventory as a test , and there icons should apper in my inventory , but thy are not doing that .
is there anyone who i can upload my files to , where he/she can see what is missing and how can i fix it ?
if yes i let me know so i can give you a link to my files
also as my first post i might not be able to post soon , so just in case that happens , leave an Emile address or a discord, so i can contact you .
Kind of difficult to follow, but you can paste your scripts directly here. Make sure to paste between three ticks like so to ensure proper formatting and syntax highlighting
```gd
# paste your script here
func your_script_here() -> void:
print("hello!")
```
hay
thank you for your replay
i have alot of script for the inventory i think 3 or 4
there is more like 16 error all about the inventory icons who are not loading
i will try to post the script as much as i can
#ItemData.gd
@icon("res://icon.svg") # Optional: replace with a custom icon for visual clarity
extends Resource
class_name ItemData
@export var name: String
@export var description: String
@export var icon: Texture2D
@export var weight: float = 1.0
@export_enum("Weapon", "Consumable", "KeyItem", "Document") var category: String
# ItemSlot.gd
extends Control # or Panel
@onready var icon_texture = $Icon # ← renamed to avoid confusion with the exported variable
@onready var name_label = $NameLabel
@onready var weight_label = $WeightLabel
var item_data: ItemData
func set_item(data: ItemData):
print("Set item called with: ", data)
print("Type: ", typeof(data))
print("Is ItemData? ", data is ItemData)
item_data = data
if icon_texture and data.icon:
icon_texture.texture = data.icon
else:
push_error("Missing icon or texture node for item: " + str(data.name))
if name_label:
name_label.text = data.name
else:
push_error("NameLabel node missing!")
if weight_label:
weight_label.text = str(data.weight) + " w"
else:
push_error("WeightLabel node missing!")
#InventoryUI.gd
extends CanvasLayer
@onready var grid = $Panel/VBoxContainer/GridContainer
@export var inventory: Inventory
@export var item_slot_scene: PackedScene # drag ItemSlot.tscn into this in the inspector
func _ready():
if inventory:
for item in inventory.items:
print("Item Loaded: ", item)
print(" Name: ", item.name)
print(" Icon: ", item.icon)
print(" Type: ", typeof(item.icon))
var slot = item_slot_scene.instantiate()
slot.set_item(item)
grid.add_child(slot)
extends Node
class_name Inventory
@export var max_weight: float = 50.0
var items: Array[ItemData] = []
# Automatically load some test items
func _ready():
var sword: ItemData = preload("res://items/sword.tres")
var potion: ItemData = preload("res://items/potion.tres")
var note: ItemData = preload("res://items/file_case42.tres")
var key: ItemData = preload("res://items/key_basement.tres")
var test_sword: ItemData = preload("res://items/test_sword.tres")
add_item(sword)
add_item(potion)
add_item(note)
add_item(key)
add_item(test_sword)
func add_item(item: ItemData) -> bool:
var total_weight = get_total_weight()
if total_weight + item.weight <= max_weight:
items.append(item)
print("Added:", item.name)
return true
else:
print("Inventory full. Couldn't add:", item.name)
return false
func get_total_weight() -> float:
var total := 0.0
for item in items:
total += item.weight
return total
#func remove_item(item: ItemData) -> void:
#items.erase(item)
the icons that should appear on the item slots are not loading , and the information’s such as the name of the item and the weight of the item are also not loading
if it would be helpful i can upload my files , its just 10 megabits
Probably the first thing to do is go through the errors and fix them. Figure out why you are “missing icon or texture node for iron_sword”. Is the icon missing? The texture? Both? Do they exist but the preload path is wrong? Is there a typo in a name?
that the problem , the textres are there , and thy are loaded into there items.tres each with its name . and proper data !
i am new to this and i cant seem to know why or what is causing this ?
You are calling set_item before the slot is a child of anything, so it cannot run it’s @onready variables, that’s why all it’s children act as if they are missing. Swap the set_item and add_child lines.
oh ok … now it worked , thank you so much !
how can i fix this “container shrinking Control”
and not sure if i should se this thread as solved or not , i might come back any time !
Your inventory has a GridContainer, this will shrink all of it’s children to their minimum size. The Control node’s minimum size is not based on it’s children. You can see in this screenshot I have your Control node selected, but I was able to drag it’s size much smaller than it’s children’s contents
If you use Containers to position and size each element then it will have the correct minimum size. Here I changed the Control to a HBoxContainer, and the labels under a VBoxContainer, now the minimum size matches it’s contents and the layout is preserved. (I also had to set the icon to expand “Fit Width”)
It’s what I find easiest. You could also set the custom minimum size property for your Control node, but then positioning it’s children can be hard to work with, especially as the screen resizes.
Yes, these $ are paths, since the NameLabel is in a different place it will require a different path. You need to add the name of your VBoxContainer inside the path. Try re-writing $NameLabel, you should see the autocomplete help you find the correct path for your scene.
With containers you cannot set the size or position of the children, the labels are automatically sized correctly. The Icon uses it’s “Expand Mode” property to find the correct size, with “Fit Width” it worked well.
oh ok cool now i see .
last thing what should i do if i want to icons to be restricted to the container of the panel and never go beyond .
i tryed scaling the itemslot size , but it never worked !