How to set all Entitys Module slots to 1

Place to get help with not working mods / modding interface.
Post Reply
TiTaN_3000
Inserter
Inserter
Posts: 45
Joined: Wed Dec 24, 2014 10:18 am
Contact:

How to set all Entitys Module slots to 1

Post by TiTaN_3000 »

Hey, i try to set all entities module slots to just one in data-final-fixes with this code:

Code: Select all

for i, entity in pairs(data.raw.entity) do
	if entity.module_slots > 1 then
	   entity.module_slots = 1
	end
end
but it says: "data-final-fixes.lua1:bad argument #1 to "pairs" (table expected, got nil)

whats wrong?

Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: How to set all Entitys Module slots to 1

Post by Choumiko »

Try this:

Code: Select all

local types = {["mining-drill"]=true,["assembling-machine"]=true,lab=true,["rocket-silo"]=true, furnace=true, beacon=true}

for t, _ in pairs(types) do
  for _, ent in pairs(data.raw[t]) do
    if type(ent.module_specification) == "table" and type(ent.module_specification.module_slots) == "number" then
      ent.module_specification.module_slots = 1
    end
  end
end
The format is data.raw[entity-type][entity], eg. data.raw["assembling-machine"]["oil-refinery"] contains the prototype of the refinery

TiTaN_3000
Inserter
Inserter
Posts: 45
Joined: Wed Dec 24, 2014 10:18 am
Contact:

Re: How to set all Entitys Module slots to 1

Post by TiTaN_3000 »

awsome, thank you very much !

Zephyrinius
Inserter
Inserter
Posts: 26
Joined: Sat Nov 12, 2016 5:55 pm
Contact:

Re: How to set all Entitys Module slots to 1

Post by Zephyrinius »

I was trying to do something similar, but when I try to access

Code: Select all

type(ent.module_specification)
I get the error
LuaEntityPrototype doesn't contain key module_specification
I'm a novice at this, and I expect the problem is something obvious.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to set all Entitys Module slots to 1

Post by eradicator »

Zephyrinius wrote:I was trying to do something similar, but when I try to access

Code: Select all

type(ent.module_specification)
I get the error
LuaEntityPrototype doesn't contain key module_specification
I'm a novice at this, and I expect the problem is something obvious.
That sounds like a control.lua error. That data is only available during data stage. And if it's during data stage then you're probably looping through something that doesn't have a module_specification...
aka: Needs way more info to answer properly.

Post Reply

Return to “Modding help”