Attempting to load packed scene from a global array

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.

Inventory Script

extends Node

var current_inventory = [0, 0, 0, 0, 0, 0, 0, 0]
var items = ["res://1.tscn", "res://2.tscn"]

func _ready():
	current_inventory[0] = items[0]
	print(current_inventory)

func add_item(slot, item):
	current_inventory[slot] = item

Player Script

extends CharacterBody2D

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

What is the error?

Invalid call. Nonexistent function ‘instantiate’ in base ‘int’.

Are you sure it’s on this line? Seems to imply you loaded a int. Maybe your loaded_item needs the @onready annotation.

I know, this line:

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.