Godot Version
Godot 4.3
Question
I’ve made an inventory system previously, and am now trying to make it so items can be used from various interactions, I’m trying to make my door object check to see if the correct key is in the inventory, and act accordingly, however I keep getting the error “attempt to call function ‘take_item_check’ in base ‘null instance’ on a null instance”, here’s the relevant code blocks:
Door Object
@onready var inventory = $"../UI/Inventory"
func open():
elif variables.isLocked == true:
if inventory.take_item_check(1000, true) == true:
variables.isLocked = false
Here’s the code for the inventory
#TAKING ITEM FROM INVENTORY (EXAMPLE: HANDING IN QUEST ITEM)
#Check to see if the player has the required item in their inventory
func take_item_check(item_ID, use):
for i in grid_array.size():
if (grid_container.get_child(i)).stored_item_ID == item_ID:
if use == true:
var used_item = grid_container.get_child(i).item_stored
take_item(used_item)
return true
elif use == false:
return true
else:
if i == grid_array.size() - 1:
return false
else:
continue
#Removing the item from the players inventory if the take_item_check function has use set to true
func take_item(used_item):
for grid in used_item.item_grids:
var grid_to_check = used_item.grid_anchor.slot_ID + grid[0] + grid[1] * col_count # use grid anchor instead of current slot to prevent bug
grid_array[grid_to_check].state = grid_array[grid_to_check].States.FREE
grid_array[grid_to_check].item_stored = null
grid_array[grid_to_check].stored_item_ID = null
used_item.queue_free()
Any help is greatly appreciated!