[2.0, Solved] How to change just one property in a mod
Posted: Thu Oct 24, 2024 10:57 am
Hello. I see in the changelog that the "utility constant pollution_color" was removed. I found another file base/prototypes/pollution.lua that defines pollution color and I'm trying to change the color with a mod.
When I copy the whole data:extends() statement from pollution.lua and change the value, it works and the color of pollution cloud changes. However, I don't want to "fix" all the other properties in case they change in a later patch.
Can someone help me with the syntax of changing just a single property value, please?
This is what I tried (I copied the approach from other mods I have installed):
This throws an error that `pollution_table` is `nil`. I don't know how to copy the table, I think I'm missing some knowledge about how the data is structured. Any help is appreciated!
Edit: I figured it out eventually. The correct syntax to access the pollution table is: data.raw["airborne-pollutant"]["pollution"]
If anyone searches for similar information, the template is data.raw([prototype-type][prototype-name]). See this https://lua-api.factorio.com/latest/types/Data.html for more information.
The type and name properties were (in my case) defined in pollution.lua (properties "type" and "name"). I am not sure if it is always like that.
When I copy the whole data:extends() statement from pollution.lua and change the value, it works and the color of pollution cloud changes. However, I don't want to "fix" all the other properties in case they change in a later patch.
Can someone help me with the syntax of changing just a single property value, please?
This is what I tried (I copied the approach from other mods I have installed):
Code: Select all
local pollution_table = table.deepcopy(data.raw["prototypes"]["pollution"]) -- or just ["pollution"]
pollution_table.chart_color = {r = 255, g = 255, b = 255, a = 0.8}
data:extend{pollution_table}
Edit: I figured it out eventually. The correct syntax to access the pollution table is: data.raw["airborne-pollutant"]["pollution"]
If anyone searches for similar information, the template is data.raw([prototype-type][prototype-name]). See this https://lua-api.factorio.com/latest/types/Data.html for more information.
The type and name properties were (in my case) defined in pollution.lua (properties "type" and "name"). I am not sure if it is always like that.
Code: Select all
-- pollution.lua
data:extend(
{
{
type = "airborne-pollutant",
name = "pollution",
-- etc
}
})