Page 1 of 1
resource category
Posted: Mon Jun 14, 2021 5:50 am
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
Re: resource category
Posted: Mon Jun 14, 2021 7:19 am
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.
Re: resource category
Posted: Mon Jun 14, 2021 8:37 am
by heloo22
thanks for reply but im sorry, turns out i need that category check inside control.lua stage.. is it even possible?
Re: resource category
Posted: Mon Jun 14, 2021 1:03 pm
by PFQNiet
Yes, if you have a reference to a resource entity you can check `entity.prototype.resource_category`.
Re: resource category
Posted: Tue Jun 15, 2021 11:12 am
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
Re: resource category
Posted: Thu Jun 24, 2021 2:24 pm
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: