resource category

Place to get help with not working mods / modding interface.
Post Reply
heloo22
Burner Inserter
Burner Inserter
Posts: 18
Joined: Wed Aug 22, 2018 11:20 am
Contact:

resource category

Post by heloo22 »

Hello, trying to get this to work in data-final stage :
if not data.raw.resource.category == "basic-fluid" then

want to do some operations on all resources except OIL/all fluid ones
could someone correct above statement, i cant get it to work

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: resource category

Post by PFQNiet »

Code: Select all

for name,resource in pairs(data.raw.resource) do
  if resource.category ~= "basic-fluid" then
    -- do stuff
  end
end
But be aware that other mods may introduce more categories.

heloo22
Burner Inserter
Burner Inserter
Posts: 18
Joined: Wed Aug 22, 2018 11:20 am
Contact:

Re: resource category

Post by heloo22 »

thanks for reply but im sorry, turns out i need that category check inside control.lua stage.. is it even possible?

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: resource category

Post by PFQNiet »

Yes, if you have a reference to a resource entity you can check `entity.prototype.resource_category`.

heloo22
Burner Inserter
Burner Inserter
Posts: 18
Joined: Wed Aug 22, 2018 11:20 am
Contact:

Re: resource category

Post by heloo22 »

Thanks you.
How people figure out the syntax is beyond me..
I looked at api factorio and found it, then proceeded trying:
entity.prototype.resource-category
entity.prototype.resource.prototype
entity.resource.category
and so on
but ofcourse couldn't get it to work

this worked for me:
for _, resource in pairs(resources) do
if resource.prototype.resource_category ~= "basic-fluid" then

andrei
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Aug 27, 2019 8:32 pm
Contact:

Re: resource category

Post by andrei »

Re. “How people figure out the syntax”. It's important to distinguish between how something (e.g. resource category) is defined and how it's used and also between data stage and control stage. You can access prototypes at both data stage (read/write) and control stage (read-only), but the syntax is different. Data stage API is documented at https://wiki.factorio.com/Prototype_definitions. Control stage API is documented at https://lua-api.factorio.com/latest/index.html.

For example in case of a resource category:

Post Reply

Return to “Modding help”