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
resource category
Re: resource category
Code: Select all
for name,resource in pairs(data.raw.resource) do
if resource.category ~= "basic-fluid" then
-- do stuff
end
end
Re: resource category
thanks for reply but im sorry, turns out i need that category check inside control.lua stage.. is it even possible?
Re: resource category
Yes, if you have a reference to a resource entity you can check `entity.prototype.resource_category`.
Re: resource category
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
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
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:
For example in case of a resource category:
- It is defined in data stage and has type “resource-category”, as shown in https://wiki.factorio.com/Prototype/ResourceCategory (on top of the page)
- It is used in data stage in ResourceEntity definition and the corresponding field is called “category”, as shown in https://wiki.factorio.com/Prototype/ResourceEntity
- It can be accessed in control stage given a LuaEntityPrototype, and the corresponding field is called “resource_category”, as shown in https://lua-api.factorio.com/latest/Lua ... otype.html