Page 1 of 1

[Solved] Odd return from item.subgroup

Posted: Wed Jul 26, 2017 6:27 am
by BrokenScience
I'm trying to find all the items with the subgroup "raw-resource" by using item.subgroup as seen on the lua api, but did not get the strings I was looking for:
Image
That was what I received as the subgroup for the wooden chest.

Here is the code I used:

Code: Select all

for __, item in pairs(game.item_prototypes) do
	if not item.has_flag("hidden") then--and item.subgroup == "raw-resource" then
	table.insert(raw, {item.name, item.subgroup})
	end
end
Should item.subgroup as used in this example give me the subgroup in the form of "raw-resource" assuming raw-resource was its subgroup?

The code is in control.lua and the result was printed to a label on the screen as a caption using this ( table.tostring() and its requirements) to turn the table to a string.

Re: Odd return from item.subgroup

Posted: Wed Jul 26, 2017 6:42 am
by DaveMcW

Code: Select all

for __, item in pairs(game.item_prototypes) do
  if not item.has_flag("hidden") and item.subgroup.name == "raw-resource" then
    table.insert(raw, {item.name, item.subgroup.name})
  end
end

Re: Odd return from item.subgroup

Posted: Wed Jul 26, 2017 7:11 am
by Mooncat
In addition to DaveMcW's answer:
Because you are working with control.lua, you should check http://lua-api.factorio.com/.
While item.subgroup is a string (name of the subgroup) in data phase, it is actually a LuaGroup in control.lua.
See LuaItemPrototype::subgroup

Re: Odd return from item.subgroup

Posted: Wed Jul 26, 2017 12:08 pm
by Helfima
hello,
if you want write any object from Factorio i have create a function to parse all properties https://github.com/Helfima/helmod/blob/ ... b.lua#L133

if you use my mod you can see propeties viewtopic.php?f=92&t=30465&start=60#p280735

Re: Odd return from item.subgroup

Posted: Thu Jul 27, 2017 12:19 am
by BrokenScience
Alright, my bad. I have no idea why I thought I read that item.subgroup would return a string.