Page 1 of 1

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

Posted: Sun Oct 28, 2018 4:58 am
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.

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

Posted: Sun Oct 28, 2018 8:19 am
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

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

Posted: Sun Oct 28, 2018 7:55 pm
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

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

Posted: Sat Nov 03, 2018 3:18 pm
by Klonan
Its fixed for 0.17