Godot Version
4.3
Question
Hello,
I was working on my game when i suddenly got this error

Here it is in formatted text:
E 0:00:00:0513 inventory.gd:44 @ _process(): Index p_index = 2 is out of bounds ((int)data.children_cache.size() - data.internal_children_front_count_cache - data.internal_children_back_count_cache = 2).
Clicking on it doesn’t do/show me anything and the game doesn’t crash either; i keep getting these errors while the game is running, and nothing looks broken.
Is there a way to fix it? i don’t even know what the problem is…

Could you post inventory.gd
for us? It’s difficult to say what’s wrong without looking at the code. My best guess is you have an array somewhere in inventory
’s that some code in the _process
method tries to loop over, and that the array gets resized somehow. But without seeing the code, this is impossible to tell.
Ok so, kinda my bad, clicking on it does show me where the error is coming from i just wasn’t doing correctly. just figured that out.
It points me towards this for loop that i have but i don’t see anything wrong with it?
for i in get_child_count() + 1:
if i == 0:
if get_child(i).has_node("Item-Tag"):
Primary = get_child(i)
if i == 1 and get_child(i) != null:
if get_child(i).has_node("Item-Tag"):
Secondary = get_child(i)
if i == 2 and get_child(i) != null:
if get_child(i).has_node("Item-Tag"):
Tertiary = get_child(i)
You are looping over the wrong number, you can’t get the last node, it should be:
for i in get_child_count():
Or you will try to fetch child [0, 1, 2, 3]
if there are 3 children
Oh yeah you’re right
I thought i had to add a 1 because of this example i found on a tutorial,
# loop for n = 0 to 7
for n in 8:
print(n)
but it works now with no errors. Thanks for the help!