How to list through all items that can be held in inventory?

Place to get help with not working mods / modding interface.
Post Reply
WarStalkeR
Burner Inserter
Burner Inserter
Posts: 19
Joined: Sat Nov 01, 2014 9:10 am
Contact:

How to list through all items that can be held in inventory?

Post by WarStalkeR »

Hello community. How can I list through all items in Factorio (vanilla and mods) that can be held in inventory?

Is there something like this?

Code: Select all

for each item in data.raw.items do
  if item.canbeininventory then
    somefunction(item)
  end
end
Thanks,
WarStalkeR.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How to list through all items that can be held in inventory?

Post by darkfrei »

:arrow: :arrow: :arrow: Updated

For data (data.lua) is

Code: Select all

for i, item in pairs (data.raw.item) do
  --if item.name == "my-item-name" then
    somefunction(item)
  --end
end
See also
viewtopic.php?f=34&t=32741
Last edited by darkfrei on Wed Aug 02, 2017 12:30 pm, edited 2 times in total.

WarStalkeR
Burner Inserter
Burner Inserter
Posts: 19
Joined: Sat Nov 01, 2014 9:10 am
Contact:

Re: How to list through all items that can be held in inventory?

Post by WarStalkeR »

darkfrei wrote:For scripting (control.lua) is

Code: Select all

for i, item in pairs (game.items) do
  --if item.name == "my-item-name" then
    somefunction(item)
  --end
end
Thanks for help. But what am I doing wrong?
Image

Code: Select all

for i, item in pairs (game.items) do
			if item.type == "item" or item.type == "ammo" or item.type == "armor" or item.type == "capsule" or item.type == "gun" or item.type == "mining-tool" or item.type == "item-with-entity-data" or item.type == "tool" or item.type == "repair-tool" then
				voidextension.functions.extend(item)
			end
		end

Bilka
Factorio Staff
Factorio Staff
Posts: 3123
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to list through all items that can be held in inventory?

Post by Bilka »

When are you calling the function? If you are doing it on load you have no access to the game object.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: How to list through all items that can be held in inventory?

Post by darkfrei »

Bilka wrote:When are you calling the function? If you are doing it on load you have no access to the game object.
It was data.lua

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: How to list through all items that can be held in inventory?

Post by Optera »

data.raw.item is only a fraction of items going to inventory.

There also are item-with-entity-data, item-with-inventory, blueprints & deconstructors, capsules, ammo, guns, armor, equipment, and probably some more i forgot.
If you want a complete list look at Creative Mode.

WarStalkeR
Burner Inserter
Burner Inserter
Posts: 19
Joined: Sat Nov 01, 2014 9:10 am
Contact:

Re: How to list through all items that can be held in inventory?

Post by WarStalkeR »

Thanks people, I found where problem was. Solved it with:

Code: Select all

for _, item in pairs (data.raw.item) do

WarStalkeR
Burner Inserter
Burner Inserter
Posts: 19
Joined: Sat Nov 01, 2014 9:10 am
Contact:

Re: How to list through all items that can be held in inventory?

Post by WarStalkeR »

Optera wrote:data.raw.item is only a fraction of items going to inventory.

There also are item-with-entity-data, item-with-inventory, blueprints & deconstructors, capsules, ammo, guns, armor, equipment, and probably some more i forgot.
If you want a complete list look at Creative Mode.
Thanks. I needed only some items types that hard to dispose of and have huge quantities stacked eventually, i.e. ores, old inseters, sodium hydroxide.

Post Reply

Return to “Modding help”