[SOLVED] ipairs list only functioning on last item Why?
Posted: Wed Sep 14, 2022 7:38 pm
Hey everyone,
I have a list/table of doors that is being iterated through with ipairs. When I tell the game to draw something for all k,v etc it does so. When I tell it to allow me to open the doors/change their status, it does because the animation updates.
However, what it doesn't do is check collision for every door. It will only check and return collision for the last door on the list and all others are ignored and I've no idea why this is happening.
I would provide the .love file as requested, but the door table is built in one file (all the doors are the same except for their x/y positions) and the iteration is done as part of the player collision check so here's a code snippet to show the code that's failing me:
The collision function is your standard box collider and DOES WORK, but only on the last item in the table.
I have rewritten this multiple ways, simplified it, used debugging techniques to figure out the length of the table, whether all items in the list are being iterated, everything. The ONLY thing I can think of that's causing this issue is that the for loop is calling a function and isn't doing so until it reaches the end of the table, but I don't know WHY it would be doing that.
Any help would be greatly appreciated.
I have a list/table of doors that is being iterated through with ipairs. When I tell the game to draw something for all k,v etc it does so. When I tell it to allow me to open the doors/change their status, it does because the animation updates.
However, what it doesn't do is check collision for every door. It will only check and return collision for the last door on the list and all others are ignored and I've no idea why this is happening.
I would provide the .love file as requested, but the door table is built in one file (all the doors are the same except for their x/y positions) and the iteration is done as part of the player collision check so here's a code snippet to show the code that's failing me:
Code: Select all
--! CHECK DOORS !--
for k,v in ipairs(doorLayout) do
if checkCollision(pPosX,pPosY,playerWidth,playerHeight,v.posX+gridSize,v.posY,doorLayout.doorWidth,doorLayout.doorHeight) and v.status == "closed" then
canPick = false
if playerUp then
la.play(sounds.openDoor,"stream",false,"sound")
v.status = "open"
end
else
canPick = true
end
end
end
I have rewritten this multiple ways, simplified it, used debugging techniques to figure out the length of the table, whether all items in the list are being iterated, everything. The ONLY thing I can think of that's causing this issue is that the for loop is calling a function and isn't doing so until it reaches the end of the table, but I don't know WHY it would be doing that.
Any help would be greatly appreciated.