I’m trying to create a basic inventory using arrays. The current_inventory represents the items actively held and the items represents a sort of dictionary to reference and add/remove items from the current_inventory. The players inventory was made a separate autoloaded script so that I may easily access the players inventory. In it’s present state it errors.
var loaded_item = load(str(global_player_inventory.current_inventory[0]))
run before Inventory Script execute _ready().
the resolution:
func use_item():
var loaded_item = load(str(global_player_inventory.current_inventory[0]))
var b = loaded_item.instantiate()
owner.add_child(b)
b.transform = $obj/obj2.global_transform
other resolution:
@onready var loaded_item = load(str(global_player_inventory.current_inventory[0]))
func use_item():
var b = loaded_item.instantiate()
owner.add_child(b)
b.transform = $obj/obj2.global_transform
As far as I can tell, global_player_inventory.current_inventory[0] will be 0. load(str(0)) won’t load a valid file.
Did you mean global_player_inventory.items[global_player_inventory.current_inventory[0]]? That would be equivalent to load(str("res://1.tscn")), which would be a valid path. In that case, you could also remove the str call, as there’s no need to convert a string to a string.