BUG

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Cardibro123
Prole
Posts: 1
Joined: Sun Jan 21, 2024 3:21 pm

BUG

Post 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?
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: BUG

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests