How to best delete an autoplace-control entry?

Place to get help with not working mods / modding interface.
Post Reply
Flux Faraday
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sat May 10, 2014 8:48 am
Contact:

How to best delete an autoplace-control entry?

Post 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

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How to best delete an autoplace-control entry?

Post 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).
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me :)
Or drop into #factorio on irc.esper.net

Flux Faraday
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sat May 10, 2014 8:48 am
Contact:

Re: How to best delete an autoplace-control entry?

Post 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.

Flux Faraday
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sat May 10, 2014 8:48 am
Contact:

Re: How to best delete an autoplace-control entry?

Post 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.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: How to best delete an autoplace-control entry?

Post 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...

Post Reply

Return to “Modding help”