Page 1 of 1
How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 10:23 am
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.
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 10:28 am
by darkfrei
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
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 11:47 am
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?
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
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 12:09 pm
by Bilka
When are you calling the function? If you are doing it on load you have no access to the game object.
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 12:31 pm
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
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 12:50 pm
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.
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 1:20 pm
by WarStalkeR
Thanks people, I found where problem was. Solved it with:
Code: Select all
for _, item in pairs (data.raw.item) do
Re: How to list through all items that can be held in inventory?
Posted: Wed Aug 02, 2017 1:22 pm
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.