Electric Network Statistics returning empty Dictionaries

Place to get help with not working mods / modding interface.
Post Reply
Crimso
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jun 12, 2022 7:21 pm
Contact:

Electric Network Statistics returning empty Dictionaries

Post by Crimso »

Hello Factorio Forum!

I am Crimso, author of an accessibility mod with the goal of making Factorio completely accessible to the blind.

I am running into an issue where when I get the electric_network_statistics value of an electric pole, the output_counts and input_counts attributes are returning empty dictionaries. I am determining they are empty using both the # operator, and attempting to iterate through the entire dictionary with the pairs function.

I have also tried get_output_count for "steam-engine" "solar-panel" etc with no results.

Perhaps I am misunderstanding something fundamental, or perhaps a bug has been discovered? Any help would be greatly appreciated!


Crimso
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jun 12, 2022 7:21 pm
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Crimso »

local ent = players[pindex].tile.ents[1]
result = ent.name
result = result .. " " .. ent.type
if ent.type == "electric-pole" then
result = result .. #ent.neighbours.copper
if next(ent.electric_network_statistics.input_counts) == nil then
print("Abandon all hope ye who enter")
end

for i, v in ipairs(ent.electric_network_statistics.input_counts) do
print("Producer " .. i .. " " .. v)
end
end
if ent.prototype.electric_energy_source_prototype ~= nil and ent.is_connected_to_electric_network() == false then
result = result .. "Not Connected"
end


Hope this helps!

Gweneph
Inserter
Inserter
Posts: 23
Joined: Thu Nov 14, 2019 11:51 pm
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Gweneph »

I have the same issue in vanilla. Maybe we need to initialize something? Here's a one liner that I ran on a map with just a solar panel, small electric pole, and radar.

Code: Select all

/c game.player.print(#game.player.surface.find_entities_filtered{name="small-electric-pole"}[1].electric_network_statistics.input_counts)
I did the same thing for output counts. They're both empty.

Qon
Smart Inserter
Smart Inserter
Posts: 2091
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Qon »

Crimso wrote:
Sun Jun 12, 2022 8:58 pm
Hope this helps!
Not as much as if you indented properly and used code tags. Your code doesn't run.
players, print and pindex are not defined. You get error messages for that. Edit: print is defined, but you probably meant game.print or game.player.print if you want it printed in game
You never printed result so you don't see it.
Don't use ipairs for dicts. Use pairs for dicts.

Mouse over to select an entity and run this code in console (prefix "/c ")

Code: Select all

local ent = game.player.selected
local result = ent.name
result = result .. " " .. ent.type
if ent.type == "electric-pole" then
    result = result .. #ent.neighbours.copper
    if next(ent.electric_network_statistics.input_counts) == nil then
        game.print("Abandon all hope ye who enter")
    end

    for i, v in pairs(ent.electric_network_statistics.input_counts) do
        game.print("Producer " .. i .. " " .. v)
    end
end
if ent.prototype.electric_energy_source_prototype ~= nil and ent.is_connected_to_electric_network() == false then
    result = result .. "Not Connected"
end
game.print(result)

Qon
Smart Inserter
Smart Inserter
Posts: 2091
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Qon »

Gweneph wrote:
Sun Jun 12, 2022 9:13 pm
I have the same issue in vanilla. Maybe we need to initialize something? Here's a one liner that I ran on a map with just a solar panel, small electric pole, and radar.

Code: Select all

/c game.player.print(#game.player.surface.find_entities_filtered{name="small-electric-pole"}[1].electric_network_statistics.input_counts)
I did the same thing for output counts. They're both empty.
Use table_size() to check size of dicts. You can't use # for that.
Also, use game.player.selected and hover over a power pole to test code easier without having to start a world with only 1 electric pole.

Crimso
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jun 12, 2022 7:21 pm
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Crimso »

my code is indented heavily because it is part of 3000 lines of code. It is printing to the command line prompt I am using to debug the program. I apologize if my formatting is wrong, I am blind and cannot see it. I used pairs initially and got the same result. Thanks for the help ;)

Crimso
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sun Jun 12, 2022 7:21 pm
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Crimso »

I tried your code and it didn't work. [Moderated by Koub : Please be civil, and don't start fights on this forum]

Edit: More specifically if anyone has had luck getting the output or energy producers tab of the electrical network statistics, I would be very grateful for a push in the right direction.

Edit2: If anyone else is having similar issues, make sure that the network in question has both producers and drainers on the electrical system or there will not be any contents in the input or output attributes.

Qon
Smart Inserter
Smart Inserter
Posts: 2091
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Qon »

Crimso wrote:
Sun Jun 12, 2022 9:48 pm
Thanks for the help ;)
Np :)
Crimso wrote:
Sun Jun 12, 2022 10:01 pm
I tried your code and it didn't work.
Why would you post that after?
And you didn't say what you tried. I got output on my computer because I tested it, if you want help then ask questions don't just say that working solutions don't work for you.
[Moderated by Koub : Response to a moderated content]

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

Re: Electric Network Statistics returning empty Dictionaries

Post by FuryoftheStars »

[Moderated by Koub : Response to a moderated content]

[Moderated by Koub : Response to a moderated content]. While you did say that you were working on something to make the game more accessible to the blind, you didn't say that you yourself were, so Qon had no way of knowing that you couldn't see the formatting.

[Moderated by Koub : Response to a moderated content]

Anyway...
Crimso wrote:
Sun Jun 12, 2022 10:01 pm
I tried your code and it didn't work.
I gave Qon's code a try in exactly the manor they said to use it, and it works for me.
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

lyvgbfh
Fast Inserter
Fast Inserter
Posts: 165
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by lyvgbfh »

[Moderated by Koub : Response to a moderated content]
Crimso wrote:
Sun Jun 12, 2022 8:58 pm
local ent = players[pindex].tile.ents[1]
Can you clarify what player.tile and player.tile.ents is? The code that sets this would show well enough.

I'm able to print simple stats mousing over a wooden power pole and running the following:

Code: Select all

/c local ent = game.player.selected for k, v in pairs(ent.electric_network_statistics.input_counts) do game.print(k .. " " .. v) end
the output of which is
fast-inserter 10371.333065987

Qon
Smart Inserter
Smart Inserter
Posts: 2091
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Qon »

[Moderated by Koub : Response to a moderated content]
Last edited by Qon on Mon Jun 13, 2022 12:31 am, edited 1 time in total.

lyvgbfh
Fast Inserter
Fast Inserter
Posts: 165
Joined: Fri Jul 10, 2020 6:48 pm
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by lyvgbfh »

[Moderated by Koub : Response to a moderated content]

Qon
Smart Inserter
Smart Inserter
Posts: 2091
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Qon »

[Moderated by Koub : Response to a moderated content]

Koub
Global Moderator
Global Moderator
Posts: 7175
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: Electric Network Statistics returning empty Dictionaries

Post by Koub »

[Koub] I know this forum is on the Internet, so it's expected somehow that people call each others names and stuff, but that won't be under my watch. I removed all the fighting bits, and tried letting the good stuff. I advise everybody in here not to reactivate the fire.
Koub - Please consider English is not my native language.

Post Reply

Return to “Modding help”