I Have a problem with my inventory code

v4.1.3

Question:

my code say:
Invalid fet index ‘0’ (on base: ‘Dictionary’)

extends TextureRect

var items :=

var grill := {}

var cell_size = 64
var ancho_grill = 0.0
var alto_grill = 0.0

func _ready():
var s = obtener_ancho_grill (self)
ancho_grill = s.x
alto_grill = s.y

for x in range(ancho_grill):
	grill[x] = {}
	for y in range(alto_grill):
		grill[x][y] = false

func insertar_items (ite) → bool:
var item_pos = ite.global_position + Vector2(cell_size / 2, cell_size / 2)
var g_pos = posicion_en_grill (item_pos)
var item_size = obtener_ancho_grill(ite)

if puede_insertar_item (g_pos.x, g_pos.y, item_size.x,  item_size.y):
	colocar_espacio_grill(g_pos.x, g_pos.y, item_size.x,  item_size.y, true)
	ite.global_position = global_position + Vector2(g_pos.x, g_pos.y) * cell_size
	items.append(ite)
	return true

else: return false

func tomar_item (pos):
var item = obtener_el_item_pos (pos)
if item == null: return null

	var item_pos = item.global_position + Vector2(cell_size / 2, cell_size / 2)
	var g_pos = posicion_en_grill(item_pos)
	var item_size = obtener_ancho_grill(item)
	colocar_espacio_grill(g_pos.x, g_pos.y, item_size.x, item_size.y, false)

	items.remove_at(items.find(item))
	return item

func obtener_el_item_pos (pos):
for it in items:
if it.get_global_rect().has_poimt(pos):
return it
return null

func obtener_ancho_grill (ite) → Dictionary:
var resultado := {}
var ls = ite.size
resultado.x = clamp(int(ls.x / cell_size), 1, 500)
resultado.y = clamp(int(ls.y / cell_size), 1, 500)

return resultado

func posicion_en_grill (pos) → Vector2:
var local_pos = pos - global_position
var resultado : Vector2

resultado.x = int(local_pos.x / cell_size)
resultado.y = int(local_pos.y / cell_size)

return resultado

func puede_insertar_item (x, y, w, h) → bool:
if x < 0 || y < 0: return false
if x + w > ancho_grill || y + h > alto_grill: return false

for i in range(x, x + w):
	for j in range(y, y + h):
		if grill[x][j]:
			return false

return true

func colocar_espacio_grill (x, y, w, h, estado):
for i in range(x, x + w):
for j in range (y, y + h):
grill[j] = estado

func insertar_item_enel_primer_espacio_habilitado (item) → bool:
for y in range(alto_grill):
for x in range(ancho_grill):
if !grill[y]:
item.global_position = global_position + Vector2(x, y) * cell_size
if insertar_items(item):
return true

return false

This means you are accessing a value in the dictionary that doesn’t exist. The debug error should point you at the line it happens with a stack trace.

Looking at the code I think it is here

func puede_insertar_item (x, y, w, h) → bool:
if x < 0 || y < 0: return false
if x + w > ancho_grill || y + h > alto_grill: return false

for i in range(x, x + w):
	for j in range(y, y + h):
		if grill[x][j]:
			return false

return true

This is the only time you access the dictionary if grill[x][j]:

If 0 isn’t a valid index then your setup of the dictionary is corrupted. And looking at that you use floats as range values. Which could be troublesome.

Put a breakpoint in your.code and step through it.