remote.call("silo_script", "add_tracked_item"... DUPLICATE ENTRIES

This subforum contains all the issues which we already resolved.
Post Reply
robertpaulson
Long Handed Inserter
Long Handed Inserter
Posts: 92
Joined: Sun Jun 18, 2017 2:21 pm
Contact:

remote.call("silo_script", "add_tracked_item"... DUPLICATE ENTRIES

Post by robertpaulson »

Hi, I just came across this small problem.

The add_tracked_item allows for duplicate entries which results in:
Image

I managed to clean it up with the commented section (in silo-script.lua), I haven't tested the if statement yet:

Code: Select all

add_tracked_item = function(item_name)
      if type(item_name) ~= "string" then error("Value for 'add_tracked_item' must be a string") end
      if not game.item_prototypes[item_name] then error("Item to add is not a valid item: "..item_name) end
	  
	  
	  table.insert(get_tracked_items(), item_name)
	 --[[ 
	 local list = get_tracked_items()
	  local hash = {}
	  local res = {}
		for k,v in pairs(list) do
		   if (not hash[v]) then
			   res[#res+1] = v
			   hash[v] = true
		   end

		end
	  global.silo_script.tracked_items = res--]]
	  
      update_players()
    end,
problem is that I cant stop it from happening, if I place:

local list = get_tracked_items()
if not list[item_name] then table.insert(get_tracked_items(), item_name) end

or similar problem still occurs (duplicates are created), if i keep as original 2 duplicates are made....

I will just keep that cleaner there just cuz it works...

cheers.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: remote.call("silo_script", "add_tracked_item"... DUPLICATE ENTRIES

Post by Klonan »

I could fix it, but really the mods shouldn't be adding things multiple times.

You can check if you item is already in the tracked list, and if it is, then don't add it to the list

If I were to fix it, I would change it to a map of ["entity-name"] = true,
However these mods are still doing something wrong regardless of if you can add duplicates

robertpaulson
Long Handed Inserter
Long Handed Inserter
Posts: 92
Joined: Sun Jun 18, 2017 2:21 pm
Contact:

Re: remote.call("silo_script", "add_tracked_item"... DUPLICATE ENTRIES

Post by robertpaulson »

Klonan wrote:
Sun Oct 28, 2018 8:19 am
I could fix it, but really the mods shouldn't be adding things multiple times.

You can check if you item is already in the tracked list, and if it is, then don't add it to the list

If I were to fix it, I would change it to a map of ["entity-name"] = true,
However these mods are still doing something wrong regardless of if you can add duplicates
the mods call that from on-init, so whenever I play with adding removing mods this happened... i kinda get what you saying but at the same time you shifting the check to happen on mod side... where it can be coded within the method itself... the latter is even more efficient... i just tried to be of help ;)

i will try your suggestion, thank you


Post Reply

Return to “Resolved Problems and Bugs”