[0.17.23] Assembly machine with a speed module switches status to low power
Posted: Sat Mar 30, 2019 5:34 pm
Hi
I'm trying to make a machine that has both a burner fuel (a mold that's being used up) and electrical supply. To achieve this I create a dummy invisible assembly machine under the one I want and use it to drain electrical energy. Using control code I check if the machine has energy, if it has and its state is not low power, the original machine can run. If the original machine is crafting, the invisible machine is given an recipe that takes close to forever to finish to simulate power drain, and when the original machine stops crafting, so does the invisible one. So far everything works.
When I add a module to the original machine, it copies the module to the invisible one as well to also increase the electrical demand. Here is where the issue arises;
When my machine with 500kw power need gets any module that increases energy usage, its starts having the status change to status number 9, aka "defines.entity_status.low_power" despite it running fine
My control-code is as following: (entity is the original machine, Drainer is the machine to simulate electricity drain)
And heres my log
As you can see it has the status "low-power" which stops the original machine, which then causes the invisible machine to stop crafting untill it has no power problem again, then it turns on again and on and on it goes.
Attached is my mod, along with a save file where the testing is done.
I'm trying to make a machine that has both a burner fuel (a mold that's being used up) and electrical supply. To achieve this I create a dummy invisible assembly machine under the one I want and use it to drain electrical energy. Using control code I check if the machine has energy, if it has and its state is not low power, the original machine can run. If the original machine is crafting, the invisible machine is given an recipe that takes close to forever to finish to simulate power drain, and when the original machine stops crafting, so does the invisible one. So far everything works.
When I add a module to the original machine, it copies the module to the invisible one as well to also increase the electrical demand. Here is where the issue arises;
When my machine with 500kw power need gets any module that increases energy usage, its starts having the status change to status number 9, aka "defines.entity_status.low_power" despite it running fine
My control-code is as following: (entity is the original machine, Drainer is the machine to simulate electricity drain)
Code: Select all
log(serpent.block(Drainer.status))
if Drainer.status ~= defines.entity_status.low_power and Drainer.status ~= defines.entity_status.no_power then
some code
else
rendering.draw_text{text="Not enough power supplied", surface = "nauvis", target = entity,alignment ="center",color = {r=1,g=0,b=0},time_to_live = 61,target_offset = {0,-0.7}}
entity.active = false
end
if entity.is_crafting() and entity.status == defines.entity_status.working then
Drainer.set_recipe("mold-crafting-invisble")
--log(serpent.block(Drainer.get_recipe().ingredients[1].name))
if Drainer.get_inventory(defines.inventory.assembling_machine_input).is_empty() then
Drainer.get_inventory(defines.inventory.assembling_machine_input).insert({name = Drainer.get_recipe().ingredients[1].name,count = 1})
end
if entity.status == defines.entity_status.item_production_overload then
Drainer.active = false
else
Drainer.active = true
end
else
Drainer.get_inventory(defines.inventory.assembling_machine_input).clear()
Drainer.get_inventory(defines.inventory.assembling_machine_output).clear()
Drainer.set_recipe(nil)
end
And heres my log
Code: Select all
335.939 Script @__KasTech_Metallurgy__/control.lua:73: 9
336.439 Script @__KasTech_Metallurgy__/control.lua:73: 4
336.939 Script @__KasTech_Metallurgy__/control.lua:73: 9
337.439 Script @__KasTech_Metallurgy__/control.lua:73: 4
337.938 Script @__KasTech_Metallurgy__/control.lua:73: 9
338.438 Script @__KasTech_Metallurgy__/control.lua:73: 4
338.939 Script @__KasTech_Metallurgy__/control.lua:73: 9
339.438 Script @__KasTech_Metallurgy__/control.lua:73: 4
339.939 Script @__KasTech_Metallurgy__/control.lua:73: 9
340.439 Script @__KasTech_Metallurgy__/control.lua:73: 4
340.938 Script @__KasTech_Metallurgy__/control.lua:73: 9
As you can see it has the status "low-power" which stops the original machine, which then causes the invisible machine to stop crafting untill it has no power problem again, then it turns on again and on and on it goes.
Attached is my mod, along with a save file where the testing is done.