Page 1 of 1

[0.15.33] copy_settings resets filter inserter filters

Posted: Sun Aug 20, 2017 5:30 pm
by aaargha
I've tried using copy_settings on some circuit controlled filter inserters for some UPS benchmarking and while it correctly copies the circuit settings is also resets the filters of all inserters. Copying using shift+right-click -> shift+left-click works as intended so I don't really see why this wouldn't do the same.

I've attached a savefile with a couple of filter inserters, below is the command I tried using, note that it correctly copies the circuit settings but not the filter settings.

Code: Select all

/c for _,ins in pairs(game.player.surface.find_entities_filtered{name="filter-inserter"}) do
	ins.copy_settings(game.player.selected)
end

Re: [0.15.33] copy_settings resets filter inserter filters

Posted: Sun Aug 20, 2017 7:04 pm
by daniel34
The bug is that calling copy_settings on an entity with the parameter set to the same entity will clear the filter.

Calling

Code: Select all

/c game.player.selected.copy_settings(game.player.selected)
while hovering over a filter inserter will clear the filter but keep the circuit conditions.

OP's code has the fault that it is called for every filter inserter on the map, including the selected one. If you first call /c x = game.player.selected with the left inserter selected, and then call /c game.player.selected.copy_settings(x) with the right inserter selected it will properly copy the filter and circuit conditions.

EDIT: Since it's only self-copying that triggers the bug the following command will do what OP intends to do, copying the filter and circuit conditions of the selected filter inserter to all other filter inserters on the map:

Code: Select all

/c for _,ins in pairs(game.player.surface.find_entities_filtered{name="filter-inserter"}) do
   if ins ~= game.player.selected then
      ins.copy_settings(game.player.selected)
   end
end

Re: [0.15.33] copy_settings resets filter inserter filters

Posted: Sun Aug 20, 2017 7:42 pm
by aaargha
I don't even want to imagine the odds of me multiple times choosing the first inserter returned by find_entities_filtered as source, especially as my test map has about 6.4k inserters :) Thanks for clarifying that.

Also, thank you for the code snippet, I used a separate command to copy the filters after setting them as a workaround, so that is a much better solution.

Re: [0.15.33] copy_settings resets filter inserter filters

Posted: Mon Aug 21, 2017 2:23 am
by Rseding91
Since this only happens when you make a mistake in the Lua code and the game doesn't have this problem I don't consider this a bug.

Copying settings from self to self could probably even be an error since there's literally no reason you should ever do it.

Re: [0.15.33] copy_settings resets filter inserter filters

Posted: Mon Aug 21, 2017 6:48 am
by posila
Rseding91 wrote:Copying settings from self to self could probably even be an error since there's literally no reason you should ever do it.
Maybe it could be NOP

Re: [0.15.33] copy_settings resets filter inserter filters

Posted: Mon Aug 21, 2017 6:52 am
by Rseding91
posila wrote:
Rseding91 wrote:Copying settings from self to self could probably even be an error since there's literally no reason you should ever do it.
Maybe it could be NOP
Ok, I changed it for 0.16 so it just does nothing if someone tries to copy settings from the same entity onto itself.

Re: [0.15.33] copy_settings resets filter inserter filters

Posted: Mon Aug 21, 2017 8:30 am
by aaargha
Thank you, that feels much more reasonable :)

Keep up the great work guys and have a great day!