[Solved] Need little help for a item filter

Place to get help with not working mods / modding interface.
Post Reply
DOSorDIE
Fast Inserter
Fast Inserter
Posts: 248
Joined: Sat Oct 11, 2014 3:43 pm
Contact:

[Solved] Need little help for a item filter

Post by DOSorDIE »

A simple question:
What must i change the line that it takes only "Coal" or "Wood"?
I konw this line is wrong ... if item = "coal" or "wood" then

Code: Select all

if #items > 0 then
				inventory = collector.getinventory(1)
				for _,item in pairs(items) do
					if item = "coal" or "wood" then
						if not item.isitemonbelt() then
							if inventory.caninsert(item.stack) then
								inventory.insert(item.stack)
								item.destroy()
								break
							end
						end
					end
				end
			end
Thank You!
Last edited by DOSorDIE on Wed May 06, 2015 8:09 am, edited 1 time in total.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Need little help for a item filter

Post by orzelek »

You can check name of the item - item.name.
It will be coal and raw-wood for those two - you might need to check names for others in data files.

Actual if needs to look like this:

Code: Select all

if item.name = "coal" or item.name = "raw-wood" then
Last edited by orzelek on Tue May 05, 2015 12:32 pm, edited 1 time in total.

DOSorDIE
Fast Inserter
Fast Inserter
Posts: 248
Joined: Sat Oct 11, 2014 3:43 pm
Contact:

Re: Need little help for a item filter

Post by DOSorDIE »

Great!
I will test it now

Thanks!

DOSorDIE
Fast Inserter
Fast Inserter
Posts: 248
Joined: Sat Oct 11, 2014 3:43 pm
Contact:

Re: Need little help for a item filter

Post by DOSorDIE »

The right one was

Code: Select all

if item.stack.name == "coal" or item.stack.name == "raw-wood" then 
because we must filter it from "item-on-ground"

But you help us to get to the right direction.

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: Need little help for a item filter

Post by rk84 »

Even though solved. I want to post additional tips.
If you have alot of item names to filter you can use table.

Code: Select all

filter = {
  coal = true,
  ["raw-wood"] = true,
  ["solid-fuel"] = true
}

--

if filter[item.stack.name] then
or if you want fuel items you can do

Code: Select all

if game.itemprototypes[item.stack.name].fuelvalue > 0 then
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

DOSorDIE
Fast Inserter
Fast Inserter
Posts: 248
Joined: Sat Oct 11, 2014 3:43 pm
Contact:

Re: [Solved] Need little help for a item filter

Post by DOSorDIE »

Thats Great ... and usefull for me.
Is there more?
For Ore as example?

Thanks!

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: [Solved] Need little help for a item filter

Post by rk84 »

hmm this one relies on naming. Name of object needs to be same in both item and entity form, which usually is the case.

Code: Select all

if game.entityprototypes[item.stack.name] and game.entityprototypes[item.stack.name].type == "resource" then
edit: little fix
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

Post Reply

Return to “Modding help”