remote.call("silo_script", "add_tracked_item"... DUPLICATE ENTRIES
Posted: Sun Oct 28, 2018 4:58 am
				
				Hi, I just came across this small problem.
The add_tracked_item allows for duplicate entries which results in:

I managed to clean it up with the commented section (in silo-script.lua),I haven't tested the if statement yet:
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.
			The add_tracked_item allows for duplicate entries which results in:

I managed to clean it up with the commented section (in silo-script.lua),
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,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.
