[Solved] Odd return from item.subgroup

Place to get help with not working mods / modding interface.
Post Reply
BrokenScience
Inserter
Inserter
Posts: 26
Joined: Thu Jul 21, 2016 5:31 pm
Contact:

[Solved] Odd return from item.subgroup

Post 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.
Last edited by BrokenScience on Tue Aug 01, 2017 1:45 am, edited 2 times in total.
Smashing a brick wall with my face would be a lot more rewarding if I didn't just reveal 3 more.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3041
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Odd return from item.subgroup

Post 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

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1174
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Odd return from item.subgroup

Post 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
My mods (Deprecated, maybe temporary... idk. Currently time/mood to continue):

Helfima
Fast Inserter
Fast Inserter
Posts: 164
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: Odd return from item.subgroup

Post 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

BrokenScience
Inserter
Inserter
Posts: 26
Joined: Thu Jul 21, 2016 5:31 pm
Contact:

Re: Odd return from item.subgroup

Post by BrokenScience »

Alright, my bad. I have no idea why I thought I read that item.subgroup would return a string.
Smashing a brick wall with my face would be a lot more rewarding if I didn't just reveal 3 more.

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: No registered users