Page 1 of 1
How to best delete an autoplace-control entry?
Posted: Sat Feb 14, 2015 7:37 am
by Flux Faraday
I'm changing the base resources in the mod I'm playing with. I can go and manually edit the autoplace-controls.lua file in base/prototypes and get exactly what I want. So I am now trying to do it properly from a mod. I need to delete the standard entries for coal and stone.
I've tried this:
Code: Select all
data.raw["autoplace-control"]["coal"] = nil
but that leaves an empty entry named coal and errors out.
I've also tried this:
Code: Select all
for i = #data.raw["autoplace-control"], 1, -1 do
if data.raw["autoplace-control"][i]["name"] == "coal" then
table.remove(data.raw["autoplace-control"],i)
end
end
which appears to do nothing at all. A pointer to a simple example of this kind of thing would be great.
Thanks
Re: How to best delete an autoplace-control entry?
Posted: Sat Feb 14, 2015 4:49 pm
by FreeER
The issue is that you only delete the autoplace control, but the entity is still trying to reference that in it's autoplace definition. The second method fails because it only works for numeric indexes (it's used to shift the other entries up and prevent a sparse table, since next/ipairs will stop at the first nil value).
Use this to delete them (or you could change the control to something that exists):
Code: Select all
data.raw["autoplace-control"]["coal"] = nil
data.raw["resource"]["coal"]["autoplace"] = nil
data.raw["autoplace-control"]["stone"] = nil
data.raw["resource"]["stone"]["autoplace"] = nil
To be honest I half expected there to also be an issue with the autoplace peaks in other entities as well, but Factorio 11.15 starts up and plays just fine with only those changes so it must be ignoring 'invalid' peaks or there's an actual noise-layer specification somewhere (though I don't remember there being one).
Re: How to best delete an autoplace-control entry?
Posted: Sat Feb 14, 2015 9:50 pm
by Flux Faraday
d'oh! I totally forgot about my edits over in entity/demo-resources.lua. You are right, data.autoplace-control and data.resource need to be changed together since they cross-reference. Thank you for this and the lua-noob answers. I'm now using "for i,v in pairs" to walk tables, and I can see the data much more clearly.
Re: How to best delete an autoplace-control entry?
Posted: Sat Feb 14, 2015 10:00 pm
by Flux Faraday
FreeER wrote:To be honest I half expected there to also be an issue with the autoplace peaks in other entities as well, but Factorio 11.15 starts up and plays just fine with only those changes so it must be ignoring 'invalid' peaks or there's an actual noise-layer specification somewhere (though I don't remember there being one).
You might be referring to tile/noise-layers.lua, which appears to just be a list of noise-layer names. That leaves the noise-layer "coal" in place, even if the resource "coal" is deleted.
Re: How to best delete an autoplace-control entry?
Posted: Sat Feb 14, 2015 10:27 pm
by FreeER
Flux Faraday wrote:Thank you for this and the lua-noob answers.
no problem, everyone learns over time
Flux Faraday wrote:I'm now using "for i,v in pairs" to walk tables, and I can see the data much more clearly.
Indeed, though unless you are doing something to everything/most, or take extra measures to break out of the loop when you're done, it can take longer with a loop than a direct access. Probably not a noticeable difference on resources/autoplace-control however
Flux Faraday wrote:You might be referring to tile/noise-layers.lua, which appears to just be a list of noise-layer names. That leaves the noise-layer "coal" in place, even if the resource "coal" is deleted.
Yes that appears to be what I was referring to

Honestly I don't deal with auto-placement and noise-layers much so I don't know/remember nearly as much about them as other topics...