Page 1 of 1

BUG

Posted: Tue Dec 10, 2024 2:48 am
by Cardibro123
I have this bug that I just don't understand.

I have this code here that loops through a tile's inputs (other tiles that are inputs to that tile) and it disconnects the wire that are between them.

(A wire is just when tile A is in tile B's inputs and tile B is in tile A's outputs or vise versa)

Code: Select all

print(#tile.inputs)
 
for i, v in pairs(tile.inputs) do
	self:disconnectWire(tile, v, true)
	print(#tile.inputs)
end
Now here is the problem, whenever it originally prints the length of the tile.inputs table (at the top) it says two. Then whenever it prints the length of the tile.inputs table (in the loop) it says one. Though the loop does not continue after that. Whenever I comment the self:disconnectWire(tile, v, true) line, the loop continues fine. Though it should happen even when it is not commented because there is still one instance left in the table.

Does anybody have an idea?

Re: BUG

Posted: Tue Dec 10, 2024 6:44 am
by zorg
Hi and welcome to the forums.

pairs is not ordered, meaning it will iterate over the tile.inputs table in whatever order it pleases; depending on what disconnectWire does, it might mess with iteration.

either try using ipairs, or if that doesn't work either (probably due to you deleting entries in the tile table), then do a simple for loop, and iterate backwards.