i try to export energy stats to file (so i can use them for my led strip), i want something like a satisfaction bar in reallive .
unfortunately my solution causes fpsdrops (1 each 60 tick).
do u know a "better" method to read values like produced energy and "used" energy?
i have only 2.3k Accumlators, 1.8k solar panels and 53 steamengines, without my mod its fine.
attached my "mod".
Re: export energy stats to file
Posted: Wed Sep 20, 2017 8:37 pm
by olafthecat
You know.
Here's a reply.
Might get someone else to fix your problem.
Issue is, I have no idea what you are are talking about.
Good luck!
Re: export energy stats to file
Posted: Wed Sep 20, 2017 9:31 pm
by Adil
Well, for me it doesn't really work because, firstly, you try to iterate over dictionary (non-number keys) with `ipairs`, secondly, because solar panel has `energy` equal to zero always. I've fixed first issue below, for the second one I don't know workaround.
require "util"
--local game_ready = true -- this is sure desync and would also cause init_energy on each game load
-- search exsisting energy things
function init_energy()
global.energy = {}
global.energy_sources = {"generator", "solar-panel", "reactor", "accumulator"}
for _, source in ipairs(global.energy_sources) do
global.energy[source] = {}
for _,surf in pairs(game.surfaces) do
local ents = surf.find_entities_filtered({type = source})
for _, ent in pairs(ents) do
global.energy[source][ent.unit_number] = ent--you don't need position, besides that can be changed
end
end
end
end
function add_energy_entity(entity)
if global.energy_sources[entity.type] then--you already hava a dictionary, no need to search through it
global.energy[entity.type][entity.unit_number] = entity
end
end
function delete_energy_entity(entity)
if global.energy_sources[entity.type] then
global.energy[entity.type][entity.unit_number] = nil
end
end
function get_entitys_energy(source)
local cur = 0
local max = 0
for _, ent in pairs(global.energy[source]) do
cur = cur + ent.energy
max = max + ent.electric_buffer_size
end
local energy = {cur = cur, max = max}
return energy
end
Maybe you should make a request, so that devs would export the energy_production_statistics per force, like they do for item_production_statistics.
Re: export energy stats to file
Posted: Thu Sep 21, 2017 5:01 am
by blendi_93
thx for ur reply.
adding new generators didnt work, cause "global.energy_sources[entity.type]" has the keys 1 2 3 4 changed to global.energy[entity.type]
HUGE thx, using entity.unit_number resolved the performance problem, next: stupid solar panels
attached my current version, if interrested.
Re: export energy stats to file
Posted: Sun Mar 25, 2018 5:40 pm
by Edris89
really looking forward to this one. cause i too wanted to react a ledstrip with factorio.
If you someone could help would be awesome