Page 1 of 1

[Rseding91] [0.18.36] Energy lost when setting energy on a heat buffer

Posted: Tue Jul 21, 2020 5:02 am
by wasmoo
I created a mod that adds heat-powered buildings. When I attempted to set the energy level of one of these buildings, the power value was set to 0, and the temperature was reduced to the min_working_temperature. (Setting temperature worked fine.)

Here's a minimalist example:

Code: Select all

-- data.lua
local heat_machine = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"])
heat_machine.name = "heat-machine"
heat_machine.energy_source = table.deepcopy(data.raw["boiler"]["heat-exchanger"].energy_source)
data:extend{heat_machine}

Code: Select all

-- control.lua

local function on_tick(e)
  local entities = game.surfaces[1].find_entities_filtered({name="heat-machine"})
  for _, entity in ipairs(entities) do
    local before = {
      temperature = entity.temperature,
      power = entity.energy,
    }
    entity.energy = entity.energy + 100 -- THIS DOESN'T WORK
    local after ={
      temperature = entity.temperature,
      power = entity.energy,
    }
    log(serpent.block{
      before = before,
      after = after,
    })
  end

end

script.on_init(function()
  script.on_event(defines.events.on_tick, on_tick)
end)

In game, I place the entity using the console:

Code: Select all

/c game.surfaces[1].create_entity{name="heat-machine",position={0,0}}
The log output looks like this:
after = {
power = 0,
temperature = 500
},
before = {
power = 0,
temperature = 500
}
}

Re: [0.18.36] Energy lost when setting energy on a heat buffer

Posted: Sat Sep 05, 2020 3:27 am
by Rseding91
Thanks for the report. It's now fixed for the next release.