Page 1 of 1

How to set all Entitys Module slots to 1

Posted: Sun Mar 27, 2016 8:34 am
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?

Re: How to set all Entitys Module slots to 1

Posted: Sun Mar 27, 2016 8:45 am
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

Re: How to set all Entitys Module slots to 1

Posted: Sun Mar 27, 2016 10:58 am
by TiTaN_3000
awsome, thank you very much !

Re: How to set all Entitys Module slots to 1

Posted: Wed Feb 07, 2018 7:34 am
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.

Re: How to set all Entitys Module slots to 1

Posted: Wed Feb 07, 2018 4:39 pm
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.