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)
Code: Select all
/c game.surfaces[1].create_entity{name="heat-machine",position={0,0}}
after = {
power = 0,
temperature = 500
},
before = {
power = 0,
temperature = 500
}
}