Get stats of accumulators on the network

Place to get help with not working mods / modding interface.
Post Reply
PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Get stats of accumulators on the network

Post by PFQNiet »

Is there any way of getting information about the total accumulator charge of an electric network?

TheBigZet
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jul 03, 2017 5:02 pm
Contact:

Re: Get stats of accumulators on the network

Post 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)

FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2530
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

Re: Get stats of accumulators on the network

Post 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.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles

Post Reply

Return to “Modding help”