Page 1 of 1

Get stats of accumulators on the network

Posted: Fri Jun 11, 2021 7:55 pm
by PFQNiet
Is there any way of getting information about the total accumulator charge of an electric network?

Re: Get stats of accumulators on the network

Posted: Wed Nov 24, 2021 8:51 pm
by TheBigZet
I know that's a bit late, but maybe it will help someone it the future :)
You'd think that

Code: Select all

electric_network_statistics
would be a solution to this problem, but apparently it can only give producers and consumers.
Here's a code that finds every accumulator connected to the same network as some power pole, and returns total charge of this network

Code: Select all

	local grid_id = <some_power-pole>.electric_network_id
	local total_charge = 0
	local accumulators = surface.find_entities_filtered{name = "accumulator"}
	for _, i in ipairs(accumulators) do
		if i.electric_network_id == grid_id then 
			total_charge = total_charge + i.energy
		end
	end
	game.print(total_charge)

Re: Get stats of accumulators on the network

Posted: Wed Nov 24, 2021 9:17 pm
by FuryoftheStars
TheBigZet wrote: Wed Nov 24, 2021 8:51 pm You'd think that

Code: Select all

electric_network_statistics
would be a solution to this problem, but apparently it can only give producers and consumers.
Maybe a good request for modding interface request section? Assuming that one does indeed not already exist.